Уведомление Firebase отображается, но при уведомлении о щелчке приложение не открываетсяAndroid

Форум для тех, кто программирует под Android
Ответить Пред. темаСлед. тема
Anonymous
 Уведомление Firebase отображается, но при уведомлении о щелчке приложение не открывается

Сообщение Anonymous »

Я использую уведомление Firebase
в своем приложении. Я получаю уведомления правильно, но когда я нажимаю на уведомление, мое приложение не открывается
это мой класс

Код: Выделить всё

public class MyFirebaseMessagingService extends FirebaseMessagingService {
Intent intent ;

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {

String body = "";
String title = "";
String type = "";
String json_Data = "";
String referenceId = "";

Log.d("FirebaseMsgService", "Message received: " + remoteMessage);

try {

if (remoteMessage.getNotification() != null) {

body = Objects.requireNonNull(remoteMessage.getNotification()).getBody();
title = remoteMessage.getNotification().getTitle();
type = remoteMessage.getNotification().getClickAction();
/* body = remoteMessage.getNotification().getBody();
title = remoteMessage.getNotification().getTitle();*/

Log.d("FirebaseMsgService", "Notification received - Title: " + title + ", Body: " + body + ", Type: " + type);

}

referenceId =   remoteMessage.getData().get("refrence_id");
//   type = remoteMessage.getData().get("click_action"); // Get the click_action

Log.d("FirebaseMsgService", "Reference ID: " + referenceId);

}catch (Exception e){
type ="";
Log.d("FirebaseMsgService", "" + e.toString());
Log.d("FirebaseMsgService",e.toString() + "" +e.getMessage().toString());
}

sendNotification(body , title , type , referenceId);

}

private void sendNotification(String body , String title , String noti_type , String postId) {

Log.d("FirebaseMsgService", "Intent Data: noti_type=" + noti_type + ", postId=" + postId);

if(noti_type.equals("disscussion_board")){
intent = new Intent(getApplicationContext(), DetailDiscussionActivity.class);
Bundle bundle = new Bundle();
bundle.putString("borad_id" , postId);
intent.putExtra( "sss" ,bundle);
} else if(noti_type.equals("sell_vehicle")){
intent = new Intent(getApplicationContext(), CarListForSaleActivty.class);
Bundle bundle = new Bundle();
bundle.putString("sell_id" , postId);
bundle.putString("title" , title);
intent.putExtra( "sss" ,bundle);
} else if (noti_type.equals("portable_charger_booking")) {
intent = new Intent(getApplicationContext(), PortableChargerBookingHistoryDetailsActivity.class);
intent.putExtra("booking_id" , postId);
intent.putExtra("title" , title);
// intent.putExtra( "sss" ,bundle);

} else if (noti_type.equals("charging_service")) {
intent = new Intent(getApplicationContext(), ChargingServiceHistoryDetailActivity.class);
intent.putExtra("service_id" , postId);
intent.putExtra("title" , title);
// intent.putExtra( "sss" ,bundle);

}else if(noti_type.equals("charging_installation_service")){
intent = new Intent(getApplicationContext(), ChargerInstallationHistoryDetailActivity.class);
intent.putExtra("requestId" , postId);
intent.putExtra("title"  , title);
}else {
intent = new Intent(getApplicationContext(), NotificationListActivity.class);
}
int requestCode = (int) System.currentTimeMillis();
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), requestCode, intent, PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);

Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, "channelId");

NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel("channelId", getString(R.string.app_name), NotificationManager.IMPORTANCE_DEFAULT);
channel.setShowBadge(true);
notificationManager.createNotificationChannel(channel);
notificationBuilder.setChannelId("channelId");
}

Bitmap largeIcon = BitmapFactory.decodeResource(getResources(),
R.mipmap.ic_launcher);

notificationBuilder.setSmallIcon(R.mipmap.ic_launcher);
notificationBuilder.setContentTitle(title)
.setContentText(body)
.setAutoCancel(true)
.setStyle(new NotificationCompat.BigTextStyle().bigText(body))
.setSound(defaultSoundUri)
.setVibrate(new long[]{1000, 1000})
.setContentIntent(pendingIntent);

Random rand = new Random();
int as = rand.nextInt();
//        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(as /* ID of notification */, notificationBuilder.build());
}
}

and nothing is printing on Logs

this is data coming from server

"message": {
"token": "dSfgsgsfdgsdfgdsfxxxxxxxxxxxxxxxxxxxxxxxxxx",
"notification": {
"title": "Completed!",
"body": "complete body ."
},
"data": {
"title": "Charging Completed!",
"body": "Charging complete, please lock your EV.",
"click_action": "portable_charger_booking",
"refrence_id": "PCB0305"
},
"apns": {
"payload": {
"aps": {
"sound": "default"
}
}
},
"android": {
"priority": "high",
"notification": {
"click_action": "portable_charger_booking"
}
}
}
}
все, что я добавил, как в манифесте Intent-filter, но основная проблема в том, что я не получаю никаких журналов при поступлении уведомления.
Я ожидаю при нажатии на уведомление мое приложение откроется

Подробнее здесь: https://stackoverflow.com/questions/792 ... ng-the-app
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Android»