【问题标题】:Start Intent after click on Push Notification单击推送通知后启动 Intent
【发布时间】:2014-03-26 21:20:12
【问题描述】:

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

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

在我写的代码下面:

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);
}

一切正常

【问题讨论】:

    标签: android android-intent push-notification


    【解决方案1】:

    您应该创建并显示一个通知,并使用待处理的意图来指定从通知开始的活动。

    例如:

        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());
    

    当点击通知时,该代码将启动活动。

    【讨论】:

    • 谢谢,我试试看!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多