我使用下面的代码作为我的接收器,我想打开应用程序,让我们说具体的活动,但它不起作用,通知点击没有任何反应:
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0)
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
Notification n = builder.setContentIntent(pIntent)
.setSmallIcon(R.drawable.ic_launcher)
.setTicker(title)
.setWhen(System.currentTimeMillis())
.setAutoCancel(true)
.setContentTitle(title)
.setContentText(msg)
.build();
n.defaults |= Notification.DEFAULT_VIBRATE;
n.defaults |= Notification.DEFAULT_SOUND;
mNotificationManager.notify(0, n);
这是我之前初步确定的意图:
Intent intent = new Intent(this, Activity_Notification.class);
这是我的清单的权限:
<permission
android:name="com.rahil.googlemapsv2.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.rahil.aidapp.googlemapsv2.permission.MAPS_RECEIVE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<permission android:name="com.rahil.aidapp.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.rahil.aidapp.permission.C2D_MESSAGE" />
这是接收器:
<receiver
android:name="com.rahil.gcm.GcmBroadcastReceiver"
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.rahil.gcm" />
</intent-filter>
</receiver>
<service android:name="com.rahil.gcm.GcmIntentService" />
答案 0 :(得分:1)
Intent resultIntent = new Intent(this, ResultActivity.class);
...
// Because clicking the notification opens a new ("special") activity, there's
// no need to create an artificial back stack.
PendingIntent resultPendingIntent =
PendingIntent.getActivity(
this,
0,
resultIntent,
PendingIntent.FLAG_UPDATE_CURRENT
);