不会从推送通知中调用活动

时间:2019-04-01 08:21:08

标签: android android-intent notifications click

您好,我不知道为什么我的应用程序没有通过通知点击调用任何活动。当然,我曾经使用getActivity来挂起意图。

如果我单击通知,MainActivity将不显示我的RegisterActivity。

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    if (remoteMessage.getData().size() > 0) {
        PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
        PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG");
        wakeLock.acquire(3000);

        String title = remoteMessage.getData().get("title");
        String body = remoteMessage.getData().get("body");
        String click_action = "RegisterActivity"; 
        sendNotification(title, body, click_action);

    }
}

private void sendNotification(String title, String messageBody, String click_action) {


    Intent notifyIntent = new Intent(this, RegisterActivity.class);
    notifyIntent(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notifyIntent, 0);

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

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "1")
    .setSmallIcon(R.mipmap.ic_launcher)
    .setContentTitle(title)
    .setContentText(messageBody)
    .setSound(defaultSoundUri)
    .setPriority(NotificationCompat.PRIORITY_DEFAULT)
    .setVibrate(new long[]{1000, 1000})
    .setLights(Color.BLUE, 1,1)
    .setContentIntent(pendingIntent)
    .setAutoCancel(true);

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    notificationManager.notify(1, builder.build());

}

Android清单

<activity
        android:launchMode="singleTask"
        android:name=".MainActivity"></activity>
    <activity android:name=".RegisterActivity"
        android:launchMode="singleTask"
        android:taskAffinity=""
        android:excludeFromRecents="true">
    </activity>

仅当我单击通知时,我才能看到MainActivity。 我的代码有什么问题?

0 个答案:

没有答案