从应用程序未打开活动的android设置通知

时间:2016-09-26 17:06:36

标签: android notifications

我检查了有关通知未开启活动的所有可能的SO问题。

Not Opening the New Activity After Clicking on the Notification Android

Clicking notification not opening app/activity

Open application after clicking on Notification

http://www.vogella.com/tutorials/AndroidNotifications/article.html

以下是我的代码:

                        Intent resultIntent = new Intent(MainApplication.this, HomeActivity.class);
                        TaskStackBuilder stackBuilder = TaskStackBuilder.create(MainApplication.this);
                        stackBuilder.addParentStack(HomeActivity.class);
                        // Adds the Intent that starts the Activity to the top of the stack
                        stackBuilder.addNextIntent(resultIntent);
                        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT);


                        NotificationCompat.Builder builder = new NotificationCompat.Builder(MainApplication.this);
                        builder.setContentTitle(notifMessage.getTitle())
                                .setContentText(notifMessage.getDescription())
                                .setAutoCancel(true);
                        builder.setContentIntent(resultPendingIntent);
                        NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
                        nm.notify(0, builder.build());

和AndroidManifest

<activity
        android:name=".HomeActivity"
        android:configChanges="locale|layoutDirection"
        android:screenOrientation="portrait"
        android:exported="true"/>

我仍然无法通过通知打开活动。

任何想法有什么问题,问题是我从MainApplication(在OneSignal.startInit中)而不是从服务

中做这一切

由于

0 个答案:

没有答案