I am unable to load the activity even after passing click_action, below is my code please suggest what is the issue that when clicking on notification i am not able to load the HELLO WORLD activity.
POST: https://fcm.googleapis.com/fcm/send
{
"to": "exVfE34wTymAo7oQjXFVaQ:APpUdLOfd2KCJwrqlZ0RyrCBXQ3T_XjVfJOhYXOVIjFAnCFpnXdT1lKern6NlKtA7YtTVgv9BJGcZuW2TfchapYMjinMTRTnTcD3pk97AzJwl73GLS-rXps_ADWgeP",
"notification": {
"title": "New FCM Message",
"body": "Hello World!",
"click_action": ".Activities.CustomerRebateConfirmation"
},
"data": {
"image": "https://www.online-image-editor.com/styles/2019/images/power_girl_editor.png"
}
}
And my SERVICE
public class MyFirebaseMessagingService extends FirebaseMessagingService {
String CHANNEL_ID="2";
String image_url=null;
Bitmap image_bitmap=null;
public MyFirebaseMessagingService() {
}
@Override
public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
if(remoteMessage.getNotification() !=null){
if(remoteMessage.getData().containsKey("image") && remoteMessage.getData().get("image")!= null){
image_url=remoteMessage.getData().get("image").toString();
image_bitmap=getBitmapFromUrl(image_url);
}
showNotification(remoteMessage.getNotification().getTitle(),remoteMessage.getNotification().getBody());
}
}
@Override
public void onNewToken(@NonNull String s) {
super.onNewToken(s);
}
private void showNotification(String title,String text){
// create notification
createNoficationChannel();
Intent intent=new Intent(getApplicationContext(), MainActivity.class);
PendingIntent pendingIntent= PendingIntent.getActivity(getApplicationContext(),
0,
intent,
PendingIntent.FLAG_ONE_SHOT);
// set sound for notification
Uri defaultNotificationSound= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder builder=new NotificationCompat.Builder(this,
CHANNEL_ID)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(title)
.setContentText(text)
.setContentIntent(pendingIntent)
.setLargeIcon(image_bitmap)
.setSound(defaultNotificationSound)
.setLights(Color.GREEN,500,200)
.setVibrate(new long[]{0, 250, 250, 250})
.setStyle(new NotificationCompat.BigPictureStyle()
.bigPicture(image_bitmap)
.bigLargeIcon(null))
.setAutoCancel(true)
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
NotificationManagerCompat notificationManagerCompat=NotificationManagerCompat.
from(this);
Long l= new Long(System.currentTimeMillis());
int i=l.intValue();
//Notification ID is unique for each notification you create
notificationManagerCompat.notify(i,builder.build());
}
public void createNoficationChannel(){
// create Notification Channel only on API level 26+
// Notification Channel is a new class and not in the support library
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
String name="All Notification Channel";
String description= "All kind of notification from Traffic checker app";
int importance= NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel channel=new NotificationChannel(CHANNEL_ID,name,importance);
channel.setVibrationPattern(new long[]{0, 250, 250, 250});
channel.setDescription(description);
//Register the channel with the system
//You cannot change importance or other notification behaviour after the this
NotificationManager manager= getSystemService(NotificationManager.class);
manager.createNotificationChannel(channel);
}
}
private Bitmap getBitmapFromUrl(String image_url) {
try {
URL url=new URL(image_url);
HttpURLConnection connection=(HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream inputStream=connection.getInputStream();
return BitmapFactory.decodeStream(inputStream);
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
AndroidManifest.xml
<application
android:name=".data.ThisApplication"
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true">
<activity
android:name=".HelloWorld" >
<intent-filter>
<action android:name=".Activities.CustomerRebateConfirmation" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>