Task 12
Task 12
package com.example.task;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;
import androidx.activity.EdgeToEdge;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.messaging.FirebaseMessaging;
TextView tvToken;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_my_profile);
setTitle("My Profile");
tvToken = findViewById(R.id.tvMyProfileToken);
FirebaseMessaging.getInstance().getToken()
.addOnCompleteListener(new OnCompleteListener<String>() {
@Override
public void onComplete(@NonNull Task<String> task) {
if (!task.isSuccessful()) {
Toast.makeText(MyProfile.this, "FCM Token not
received", Toast.LENGTH_SHORT).show();
return;
}
@Override
public void onBackPressed() {
super.onBackPressed();
Intent i = new Intent(MyProfile.this, HomeActivity.class);
startActivity(i);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MyProfile">
<TextView
android:layout_margin="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tvMyProfileToken"
android:text=""/>
</LinearLayout>