我已经使用解析实现了推送。将参数添加到 list 文件:
<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 方法...
我需要它用于 Parse-Analytics。
操作 com.parse.push.intent.RECEIVE
被触发,因为方法 onPushReceive 被调用。 com.parse.push.intent.DELETE
和 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);
基本上我们需要在您的 notificationbuilder 上添加这两个操作。
关于android - 解析 onPushOpen 从未调用过,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27805645/