解析onPushOpen从来没有所谓的 [英] Parse onPushOpen never called

查看:93
本文介绍了解析onPushOpen从来没有所谓的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了用解析推。添加参数清单文件:

 <接收
        机器人:名字=com.emaborsa.cablePark.parse.GcmBroadcastReceiver
        机器人:出口=假>
        &所述;意图滤光器>
            <作用机器人:名字=com.parse.push.intent.RECEIVE/>
            <作用机器人:名字=com.parse.push.intent.DELETE/>
            <作用机器人:名字=com.parse.push.intent.OPEN/>
        &所述; /意图滤光器>
    < /接收器>

Java的code:

 公共无效的onReceive(上下文的背景下,意图意图){
    NotificationManager mNotificationManager =(NotificationManager)上下文
            .getSystemService(Context.NOTIFICATION_SERVICE);
    。字符串文本= context.getResources()的getString(R.string.msg_newDataEp);
    的PendingIntent contentIntent = PendingIntent.getActivity(背景下,0,意向,Intent.FLAG_ACTIVITY_CLEAR_TOP);    NotificationCompat.Builder mBuilder =新NotificationCompat.Builder(上下文)
            .setContentText(文本)
            .setContentIntent(co​​ntentIntent)
            .setContentTitle(context.getResources()的getString(R.string.cableparks));    mNotificationManager.notify(NOTIFICATION_ID,mBuilder.build());    ((震动)context.getSystemService(Context.VIBRATOR_SERVICE))振动(500);    的setResult code(Activity.RESULT_OK);
}
@覆盖
保护无效onPushOpen(上下文的背景下,意图意图){
    ParseAnalytics.trackAppOpenedInBackground(意向);
}

我收到我所有的测试手机的推送,而是通过点击通知的方法onPushOpened永远不会被调用...
我需要它的解析,分析。
由于该方法onPushReceive被称为行动 com.parse.push.intent.RECEIVE 被激发。 com.parse.push.intent.DELETE com.parse.push.intent.OPEN 似乎从来没有被解雇,因为这些方法从来不被称为...
提示?


解决方案

终于找到了解决办法!

在您的GetNotification添加此()

\r
\r

捆绑额外= intent.getExtras();\r
随机随机=新的随机();\r
INT contentIntentRequest code = random.nextInt();\r
INT deleteIntentRequest code = random.nextInt();\r
串的packageName = context.getPackageName();\r
意图contentIntent =新意图(com.parse.push.intent.OPEN);\r
contentIntent.putExtras(临时演员);\r
contentIntent.setPackage(的packageName);\r
意图deleteIntent =新意图(com.parse.push.intent.DELETE);\r
deleteIntent.putExtras(临时演员);\r
deleteIntent.setPackage(的packageName);\r
的PendingIntent pContentIntent = PendingIntent.getBroadcast(背景下,contentIntentRequest code,contentIntent,为0x8000000);\r
的PendingIntent pDeleteIntent = PendingIntent.getBroadcast(背景下,deleteIntentRequest code,deleteIntent,为0x8000000);\r
\r
\r
位图notificationLargeIconBitmap = BitmapFactory.de codeResource(context.getResources(),R.drawable.ic_launcher);\r
NotificationCompat.Builder mBuilder =\r
新NotificationCompat.Builder(上下文)\r
.setSmallIcon(R.drawable.ic_launcher)\r
.setLargeIcon(notificationLargeIconBitmap)\r
.setContentIntent(pContentIntent).setDeleteIntent(pDeleteIntent)\r
.setContentTitle(职称)\r
.setGroup(999)\r
.setSound(Uri.parse(android.resource://+ context.getPackageName()+/+ ID))\r
.setGroupSummary(真)\r
.setContentText(文本)\r
// .setDefaults(Notification.DEFAULT_ALL)\r
.setNumber(++ numMessages);

\r

\r
\r

基本上,我们必须对自己的notificationbuilder添加这两个动作。

I have implemented the pushes using parse. added the parameters to the manifest file:

    <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 code:

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);
}

I receive the pushes on all my test phones, but by clicking the notification the method onPushOpened is never called... I need it for the Parse-Analytics. The action com.parse.push.intent.RECEIVE is fired since the method onPushReceive is called. com.parse.push.intent.DELETE and com.parse.push.intent.OPEN seem to never be fired, since the methods are never called... Hints?

解决方案

Finally found a solution!

Add this in your 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);

Basically we need to add both actions on your notificationbuilder.

这篇关于解析onPushOpen从来没有所谓的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆