我已经使用解析实现了推送。将参数添加到清单文件中:
<receiver
android:name="com.emaborsa.cablePark.parse.GcmBroadcastReceiver"
android:exported="false" >
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
Java代码:
public void onReceive(Context context, Intent intent) {
NotificationManager mNotificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
String text = context.getResources().getString(R.string.msg_newDataEp);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, Intent.FLAG_ACTIVITY_CLEAR_TOP);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
.setContentText(text)
.setContentIntent(contentIntent)
.setContentTitle(context.getResources().getString(R.string.cableparks));
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
((Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE)).vibrate(500);
setResultCode(Activity.RESULT_OK);
}
@Override
protected void onPushOpen(Context context, Intent intent) {
ParseAnalytics.trackAppOpenedInBackground(intent);
}
我在所有测试手机上收到推送,但通过单击通知,永远不会调用 onPushOpened 方法...
我需要它来进行解析分析。
那个行动com.parse.push.intent.RECEIVE
自调用方法 onPushReceive 后被触发。com.parse.push.intent.DELETE
and com.parse.push.intent.OPEN
似乎永远不会被解雇,因为这些方法从未被调用......
提示?
终于找到解决办法了!
将其添加到您的 getNotification() 中
Bundle extras = intent.getExtras();
Random random = new Random();
int contentIntentRequestCode = random.nextInt();
int deleteIntentRequestCode = random.nextInt();
String packageName = context.getPackageName();
Intent contentIntent = new Intent("com.parse.push.intent.OPEN");
contentIntent.putExtras(extras);
contentIntent.setPackage(packageName);
Intent deleteIntent = new Intent("com.parse.push.intent.DELETE");
deleteIntent.putExtras(extras);
deleteIntent.setPackage(packageName);
PendingIntent pContentIntent = PendingIntent.getBroadcast(context, contentIntentRequestCode, contentIntent, 0x8000000);
PendingIntent pDeleteIntent = PendingIntent.getBroadcast(context, deleteIntentRequestCode, deleteIntent, 0x8000000);
Bitmap notificationLargeIconBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setLargeIcon(notificationLargeIconBitmap)
.setContentIntent(pContentIntent).setDeleteIntent(pDeleteIntent)
.setContentTitle(title)
.setGroup("999")
.setSound(Uri.parse("android.resource://" + context.getPackageName() + "/" +id))
.setGroupSummary (true)
.setContentText(text)
// .setDefaults(Notification.DEFAULT_ALL)
.setNumber(++numMessages);
基本上我们需要在您的通知生成器上添加这两个操作。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)