我想要在通知發出後顯示activity
而不點擊通知Activity
必須打開。我正在使用FCM
進行通知發送。如何在沒有點擊通知的情況下顯示活動
如何在不點擊通知的情況下打開Activity
?
我使用這一點,但它不會打開活動:
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseMsgService";
String messageContent = "";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// TODO(developer): Handle FCM messages here.
messageContent = remoteMessage.getData().get("message");
showNotification(remoteMessage.getData().get("message"));
postToastMessage(remoteMessage.getData().get("message"));
Log.d(TAG, "From: " + remoteMessage.getFrom());
}
public void postToastMessage(final String message) {
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(), message +" received", Toast.LENGTH_LONG).show();
Intent newIntent = new Intent(MyFirebaseMessagingService.this, CallActivity.class);
newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(newIntent);
}
});
}
private void showNotification(String message) {
Intent i = new Intent(this, CallActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this,0,i,PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = (NotificationCompat.Builder) new NotificationCompat.Builder(this)
.setAutoCancel(true)
.setContentTitle(" Test")
.setContentText(message)
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(pendingIntent);
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
manager.notify(0,builder.build());
}
}
我收到此錯誤
FA: Discarding data. Failed to send event to service
而且你要接受'onTokenRefresh()'什麼樣的通知? –
onTokenRefresh()如果你知道任何其他請告訴我,它僅由firebase給出 – Lassie
。我將更改 – Lassie