Android 显示解析通知,打开操作不';不要开始活动

Android 显示解析通知,打开操作不';不要开始活动,android,android-intent,notifications,parse-platform,push-notification,Android,Android Intent,Notifications,Parse Platform,Push Notification,我有一些接收推送数据的解析代码,并设置了一个通知,该通知工作正常,但问题是onPushOpen声明。我想在我的应用程序中打开一个特定的活动,但onPushOpen似乎从未被调用,或者根本不工作 这是我的代码: public class NotificationReceiver extends ParsePushBroadcastReceiver { private static final String TAG = "MYTAG"; @Override public v

我有一些接收推送数据的解析代码,并设置了一个通知,该通知工作正常,但问题是onPushOpen声明。我想在我的应用程序中打开一个特定的活动,但onPushOpen似乎从未被调用,或者根本不工作

这是我的代码:

public class NotificationReceiver extends ParsePushBroadcastReceiver {
    private static final String TAG = "MYTAG";


   @Override
    public void onReceive(Context context, Intent intent) {
       Parse.setLogLevel(Parse.LOG_LEVEL_VERBOSE);
        Log.i(TAG, "Notification received");
        Bundle extras = intent.getExtras();
        String message = extras != null ? extras.getString("com.parse.Data") : "";
        JSONObject jObject;
        String alert = null;
        String title = null;
        try {
            jObject = new JSONObject(message);
            alert = (jObject.getString("alert"));
            title = (jObject.getString("title"));
        }
        catch (JSONException e) {
            e.printStackTrace();
        }

        Log.i(TAG,"alert is " + alert);
        Log.i(TAG,"title is " + title);
        NotificationCompat.Builder notification =
                new NotificationCompat.Builder(context)
                        .setSmallIcon(R.drawable.ic_launcher)
                        .setContentTitle(alert)
                        .setContentText(title);


        NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(1, notification.build());
        Log.i(TAG, "Notification created");

   }


    @Override
    protected void onPushOpen(Context context, Intent intent) {
        Log.i(TAG, "Notification clicked");
        Intent i = new Intent(context, MainActivity.class);
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i);
    }
}

我似乎不明白为什么onPushOpen不启动我请求的活动(MainActivity)。任何帮助都将不胜感激。

我在使用
onPushOpen()
方法时也面临同样的问题,但是如果您只想打开活动,还有一些工作要做。您可以使用以下方法解决此问题:

NotificationCompat.Builder notification =
            new NotificationCompat.Builder(context)
                    .setSmallIcon(R.drawable.ic_launcher)
                    .setContentTitle(alert)
                    .setContentText(title);

// create intent to start your activity
Intent activityIntent = new Intent(context, MainActivity.class);

// create pending intent and add activity intent
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, activityIntent,
    PendingIntent.FLAG_UPDATE_CURRENT);
notification.setContentIntent(pendingIntent);

// Add as notification
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(1, notification.build());

因此,无需调用
onPushOpen()
方法,因为只要单击通知,挂起的意图就会启动您的活动。

无错误。在按下/点击/点击通知时没有发生任何事情您知道调用了
onPushOpen()
吗?我不知道。据我在parse docs中发现的,单击通知时会调用onPushOpen。但是,我没有看到我在方法开头写的日志消息。。。