mirror of
https://github.com/vernu/textbee.git
synced 2026-05-19 05:46:23 -04:00
get fcm token on updateGatewayKey btn clicked
This commit is contained in:
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -3,7 +3,7 @@
|
||||
<component name="DesignSurface">
|
||||
<option name="filePathToZoomLevelMap">
|
||||
<map>
|
||||
<entry key="app/src/main/res/layout/activity_main.xml" value="0.1" />
|
||||
<entry key="app/src/main/res/layout/activity_main.xml" value="0.27088470458984376" />
|
||||
</map>
|
||||
</option>
|
||||
</component>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
plugins {
|
||||
id 'com.android.application'
|
||||
id 'com.google.gms.google-services'
|
||||
}
|
||||
|
||||
android {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.vernu.sms.activities;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
@@ -14,7 +15,10 @@ import android.widget.EditText;
|
||||
import android.widget.Switch;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.android.gms.tasks.OnCompleteListener;
|
||||
import com.google.android.gms.tasks.Task;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.google.firebase.messaging.FirebaseMessaging;
|
||||
import com.vernu.sms.R;
|
||||
import com.vernu.sms.helpers.SharedPreferenceHelper;
|
||||
|
||||
@@ -23,7 +27,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
private Context mContext;
|
||||
|
||||
private Switch gatewaySwitch;
|
||||
private EditText gatewayKeyEditText;
|
||||
private EditText gatewayKeyEditText, fcmTokenEditText;
|
||||
private Button updateKeyButton, grantSMSPermissionBtn;
|
||||
|
||||
private static final int SEND_SMS_PERMISSION_REQUEST_CODE = 0;
|
||||
@@ -37,6 +41,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
setContentView(R.layout.activity_main);
|
||||
gatewaySwitch = findViewById(R.id.gatewaySwitch);
|
||||
gatewayKeyEditText = findViewById(R.id.gatewayKeyEditText);
|
||||
fcmTokenEditText = findViewById(R.id.fcmTokenEditText);
|
||||
updateKeyButton = findViewById(R.id.updateKeyButton);
|
||||
grantSMSPermissionBtn = findViewById(R.id.grantSMSPermissionBtn);
|
||||
|
||||
@@ -59,6 +64,19 @@ public class MainActivity extends AppCompatActivity {
|
||||
public void onClick(View view) {
|
||||
String newKey = gatewayKeyEditText.getText().toString();
|
||||
SharedPreferenceHelper.setSharedPreferenceString(mContext, "GATEWAY_KEY", newKey);
|
||||
|
||||
FirebaseMessaging.getInstance().getToken()
|
||||
.addOnCompleteListener(new OnCompleteListener<String>() {
|
||||
@Override
|
||||
public void onComplete(@NonNull Task<String> task) {
|
||||
if (!task.isSuccessful()) {
|
||||
return;
|
||||
}
|
||||
String token = task.getResult();
|
||||
Toast.makeText(MainActivity.this, token, Toast.LENGTH_SHORT).show();
|
||||
fcmTokenEditText.setText(token);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -44,13 +44,24 @@
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/fcmTokenEditText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:ems="10"
|
||||
android:gravity="start|top"
|
||||
android:inputType="textMultiLine"
|
||||
app:layout_constraintEnd_toEndOf="@+id/gatewayKeyEditText"
|
||||
app:layout_constraintStart_toStartOf="@+id/gatewayKeyEditText"
|
||||
app:layout_constraintTop_toBottomOf="@+id/gatewayKeyEditText" />
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="409dp"
|
||||
android:layout_height="606dp"
|
||||
app:layout_constraintBottom_toTopOf="@+id/grantSMSPermissionBtn"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/updateKeyButton">
|
||||
app:layout_constraintTop_toBottomOf="@+id/fcmTokenEditText">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
@@ -58,4 +69,5 @@
|
||||
android:orientation="vertical"></LinearLayout>
|
||||
</ScrollView>
|
||||
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
Reference in New Issue
Block a user