我在Android应用上挣扎,只要点击所有传入的推送通知,就可以将应用重定向到特定的活动页面。我是android开发的新手,对我的编程感到抱歉。
以下是推送通知部分的android manifest.xml。感谢对此主题有任何评论: -
<!-- GCM requires a Google account. -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<permission
android:name="com.younginnovators.sjk.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<!-- VERY IMPORTANT! Don't forget this permission, or in-app billing won't work. -->
<uses-permission android:name="com.younginnovators.sjk.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<application
android:allowBackup="true"
android:icon="@mipmap/icon"
android:label="@string/app_name"
android:largeHeap="true"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Push Notifications Receiver -->
<receiver
android:name=".backgroundservices.PushNotificationBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.younginnovators.sjk" />
</intent-filter>
</receiver>
<!-- /Push Notifications Receiver -->
<!-- Push Notifications Service -->
<service android:name=".backgroundservices.PushnotificationService" />
<!-- /Push Notifications Service -->
答案 0 :(得分:1)
您可以尝试这样的事情
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, message, when);
Intent notificationIntent = new Intent(context, HomeActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent = PendingIntent.getActivity(context, 0,
notificationIntent, 0);
notification.setLatestEventInfo(context, title, message, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, notification);