android - 解析 onPushOpen 从未调用过

标签 android parse-platform google-cloud-messaging

我已经使用解析实现了推送。将参数添加到 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.DELETEcom.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/

相关文章:

android - GCM - pubSub.subscribe 不工作

android - 从 SQLite DB 中获取图像并在 WebView 中显示它们的最佳方法 (Android)

android - 如何使用 android studio 将 TIKA 添加到 build.gradle 中?

android - 我可以在应用关闭时更改推送通知的声音吗?

php - GCM 返回错误 : field data must be a json array

javascript - Parse.com - 如何阻止新用户在注册后看到他们不应该看到的内容?

android - Proguard (R8) 混淆自定义 View 名称

android - 使用 2 行文本创建自定义按钮

parse-platform - ParseFile 是否有 ACL

android - 解析facebook登录空指针异常