0% found this document useful (0 votes)
14 views4 pages

Task 12

The document discusses how to get the Firebase Cloud Messaging (FCM) registration token and display it in an Android app. It shows code for an activity that gets the FCM token and displays it on the screen, and allows clicking to view another activity.

Uploaded by

yash35567
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)
14 views4 pages

Task 12

The document discusses how to get the Firebase Cloud Messaging (FCM) registration token and display it in an Android app. It shows code for an activity that gets the FCM token and displays it on the screen, and allows clicking to view another activity.

Uploaded by

yash35567
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/ 4

Task 12:- Push NoTificaTioN WiTh fcm

CODING:-MYPROFILEACTIVITY.java

package com.example.smcreation;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
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 MyProfileActivity extends AppCompatActivity {

TextView tvInfo;
TextView tvToken;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_profile);
tvInfo =findViewById(R.id.tvInfo);
tvToken = findViewById(R.id.tvtoken);
setTitle("My Profile");
FirebaseMessaging.getInstance().getToken()
.addOnCompleteListener(new OnCompleteListener<String>() {
@Override
public void onComplete(@NonNull Task<String> task) {
if (!task.isSuccessful()) {
return;
}

// Get new FCM registration token


String token = task.getResult();
tvToken.setText(token);
Toast.makeText(MyProfileActivity.this, token, Toast.LENGTH_SHORT).show();
}
});
tvInfo.setOnClickListener(v -> {
Intent i = new Intent(MyProfileActivity.this,InfoActivity.class);
startActivity(i);

Toast.makeText(MyProfileActivity.this,"Info Activity",Toast.LENGTH_SHORT).show();

});

Toast.makeText(MyProfileActivity.this, "My Profile", Toast.LENGTH_SHORT).show();


}
@Override
public void onBackPressed() {
super.onBackPressed();
Intent intent = new Intent(MyProfileActivity.this, HomeActivity.class);
startActivity(intent);

You might also like