0% found this document useful (0 votes)
7 views2 pages

Task 12

Uploaded by

Gauri Nilakhe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Task 12

Uploaded by

Gauri Nilakhe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

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;

public class MyProfile extends AppCompatActivity {

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;
}

// Get new FCM registration token


String token = task.getResult();
tvToken.setText(token);
Toast.makeText(MyProfile.this, token,
Toast.LENGTH_SHORT).show();
}
});
}

@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>

You might also like