Skip to content

Send and receive SMS messages using your Android phone programmatically via a simple HTTP API

feat: add qrcode scanner

asherwuef60299bc0e3
diff --git a/android/app/build.gradle b/android/app/build.gradle
index 7416c22e..ceb73cbb 100644
--- a/android/app/build.gradle
+++ b/android/app/build.gradle
@@ -52,6 +52,7 @@ android {
dependencies {
implementation platform('com.google.firebase:firebase-bom:32.7.4')
+ implementation 'com.journeyapps:zxing-android-embedded:4.3.0'
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.google.firebase:firebase-messaging-ktx'
implementation 'com.squareup.okhttp3:okhttp:4.10.0'
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index f04d6f26..cf5ef65c 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -45,6 +45,11 @@
tools:ignore="LockedOrientationActivity" />
<activity android:name=".SettingsActivity" android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity" />
+ <activity
+ android:name="com.journeyapps.barcodescanner.CaptureActivity"
+ android:screenOrientation="portrait"
+ tools:replace="screenOrientation"
+ tools:ignore="DiscouragedApi" />
<service
android:name=".services.StickyNotificationService"
diff --git a/android/app/src/main/java/com/httpsms/LoginActivity.kt b/android/app/src/main/java/com/httpsms/LoginActivity.kt
index 61e92190..5cae08e7 100644
--- a/android/app/src/main/java/com/httpsms/LoginActivity.kt
+++ b/android/app/src/main/java/com/httpsms/LoginActivity.kt
@@ -23,6 +23,8 @@ import com.google.android.material.button.MaterialButton
import com.google.android.material.progressindicator.LinearProgressIndicator
import com.google.android.material.textfield.TextInputEditText
import com.google.android.material.textfield.TextInputLayout
+import com.journeyapps.barcodescanner.ScanContract
+import com.journeyapps.barcodescanner.ScanOptions
import timber.log.Timber
import java.net.URI
@@ -36,6 +38,29 @@ class LoginActivity : AppCompatActivity() {
setPhoneNumber()
disableSim2()
setServerURL()
+ val apiKeyInputLayout = findViewById<TextInputLayout>(R.id.loginApiKeyTextInputLayout)
+ apiKeyInputLayout.setEndIconOnClickListener {
+ startQrCodeScan()
+ }
+ }
+
+ private val barcodeLauncher = registerForActivityResult(ScanContract()) { result ->
+ if (result.contents != null) {
+ val apiKeyInput = findViewById<TextInputEditText>(R.id.loginApiKeyTextInput)
+ apiKeyInput.setText(result.contents)
+ Toast.makeText(this, "Scanned: ${result.contents}", Toast.LENGTH_LONG).show()
+ } else {
+ Toast.makeText(this, "Scan cancelled", Toast.LENGTH_SHORT).show()
+ }
+ }
+
+ private fun startQrCodeScan() {
+ val options = ScanOptions()
+ options.setPrompt("Scan a QR code")
+ options.setBeepEnabled(true)
+ options.setOrientationLocked(false)
+ options.setCameraId(0)
+ barcodeLauncher.launch(options)
}
override fun onStart() {
diff --git a/android/app/src/main/res/layout/activity_login.xml b/android/app/src/main/res/layout/activity_login.xml
index 0a1f046c..ccfa768e 100644
--- a/android/app/src/main/res/layout/activity_login.xml
+++ b/android/app/src/main/res/layout/activity_login.xml
@@ -41,10 +41,13 @@
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- app:errorEnabled="true"
android:hint="@string/text_area_api_key"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintTop_toTopOf="parent"
+ app:errorEnabled="true"
+ app:endIconMode="custom"
+ app:endIconDrawable="@android:drawable/ic_menu_camera"
+ app:endIconContentDescription="cameraButton"
+ app:layout_constraintBottom_toTopOf="@+id/loginPhoneNumberLayoutSIM1"
+ app:layout_constraintTop_toBottomOf="@+id/textView"
tools:layout_editor_absoluteX="16dp">
<com.google.android.material.textfield.TextInputEditText
@@ -53,7 +56,6 @@
android:layout_height="wrap_content"
android:inputType="textMultiLine"
tools:ignore="TextContrastCheck" />
-
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
@@ -131,7 +133,6 @@
android:id="@+id/linearLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_weight="50"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
@@ -164,4 +165,4 @@
tools:layout_editor_absoluteX="16dp" />
</LinearLayout>
-</androidx.constraintlayout.widget.ConstraintLayout>
+</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
diff --git a/web/package.json b/web/package.json
index 32c0d6e2..02180213 100644
--- a/web/package.json
+++ b/web/package.json
@@ -38,6 +38,7 @@
"moment": "^2.30.1",
"nuxt": "^2.18.1",
"nuxt-highlightjs": "^1.0.3",
+ "qrcode": "^1.5.0",
"ufo": "^1.5.4",
"vue": "^2.7.16",
"vue-chartjs": "^5.3.1",
diff --git a/web/pages/settings/index.vue b/web/pages/settings/index.vue
index 1771182f..1fe294b4 100644
--- a/web/pages/settings/index.vue
+++ b/web/pages/settings/index.vue
@@ -82,6 +82,26 @@
copy-text="Copy API Key"
notification-text="API Key copied successfully"
></copy-button>
+ <v-btn
+ color="primary"
+ @click="showQrCodeDialog = true"
+ class="ml-4"
+ >
+ <v-icon left>{{ mdiQrcode }}</v-icon>
+ Show QR Code
+ </v-btn>
+ <v-dialog v-model="showQrCodeDialog" max-width="400px">
+ <v-card>
+ <v-card-title>API Key QR Code</v-card-title>
+ <v-card-text>
+ <canvas ref="qrCodeCanvas"></canvas>
+ </v-card-text>
+ <v-card-actions>
+ <v-spacer></v-spacer>
+ <v-btn color="primary" text @click="showQrCodeDialog = false">Close</v-btn>
+ </v-card-actions>
+ </v-card>
+ </v-dialog>
<v-btn
v-if="$vuetify.breakpoint.lgAndUp"
class="ml-4"
@@ -714,7 +734,9 @@ import {
mdiLinkVariant,
mdiEyeOff,
mdiSquareEditOutline,
+ mdiQrcode,
} from '@mdi/js'
+import QRCode from 'qrcode'
import { ErrorMessages } from '~/plugins/errors'
import LoadingButton from '~/components/LoadingButton.vue'
@@ -731,6 +753,7 @@ export default Vue.extend({
mdiAccountCircle,
mdiShieldCheck,
mdiDelete,
+ mdiQrcode,
mdiLinkVariant,
mdiContentSave,
mdiSquareEditOutline,
@@ -741,6 +764,7 @@ export default Vue.extend({
showDiscordEdit: false,
showRotateApiKey: false,
rotatingApiKey: false,
+ showQrCodeDialog: false,
activeWebhook: {
id: null,
url: '',
@@ -803,6 +827,15 @@ export default Vue.extend({
})
},
},
+ watch: {
+ showQrCodeDialog(newVal) {
+ if (newVal && this.apiKey) {
+ this.$nextTick(() => {
+ this.generateQrCode(this.apiKey);
+ });
+ }
+ },
+ },
async mounted() {
await Promise.all([
this.$store.dispatch('clearAxiosError'),
@@ -818,6 +851,16 @@ export default Vue.extend({
},
methods: {
+ generateQrCode(text) {
+ const canvas = this.$refs.qrCodeCanvas;
+ if (canvas) {
+ QRCode.toCanvas(canvas, text, { errorCorrectionLevel: 'H' }, (err) => {
+ if (err) {
+ console.error(err);
+ }
+ });
+ }
+ },
updateEmailNotifications() {
this.notificationSettings = {
webhook_enabled:
diff --git a/web/pnpm-lock.yaml b/web/pnpm-lock.yaml
index b4e47417..926b6825 100644
--- a/web/pnpm-lock.yaml
+++ b/web/pnpm-lock.yaml
@@ -56,6 +56,9 @@ importers:
nuxt-highlightjs:
specifier: ^1.0.3
version: 1.0.3
+ qrcode:
+ specifier: ^1.5.0
+ version: 1.5.0
ufo:
specifier: ^1.5.4
version: 1.5.4