Android 单击推送通知后启动意图

Android 单击推送通知后启动意图,android,android-intent,push-notification,Android,Android Intent,Push Notification,嗯,我正在开发推送通知功能。它在收到推送消息后立即启动意图。但是我想在用户单击通知后启动意图 那么,我该怎么做呢?如何检测用户点击收到的消息 下面是我编写的代码: public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub Log.d("ALERT", "Message Received"); Intent screen2 = new Intent(

嗯,我正在开发推送通知功能。它在收到推送消息后立即启动意图。但是我想在用户单击通知后启动意图

那么,我该怎么做呢?如何检测用户点击收到的消息

下面是我编写的代码:

public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub
    Log.d("ALERT", "Message Received");

    Intent screen2 = new Intent(context, Tela2.class);
    screen2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(screen2);
}

它工作正常

您应该创建并显示通知,并使用挂起的意图指定从通知开始的活动

例如:

    mNotificationManager = (NotificationManager)
            context.getSystemService(Context.NOTIFICATION_SERVICE);

    PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
            new Intent(context, Tela2.class), 0);

    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
    .setSmallIcon(R.drawable.ic_stat_gcm)
    .setContentTitle("GCM Notification")
    .setStyle(new NotificationCompat.BigTextStyle()
    .bigText(msg))
    .setContentText(msg);

    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());

该代码将在单击通知时启动活动。

谢谢,让我试试!