Parse.com android 通知 - 获取数据到 BroadcastReceiver

Parse.com android notification - get data into BroadcastReceiver

我需要帮助实现 ParsePushBroadcastReceiver, 为了用它来解析一个 JSON 对象,选择一个 Activity 开始。

我试过:

 <receiver
            android:name="com......BroadcastReceiver"
            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>

<receiver android:name="com....BroadcastReceiver">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.USER_PRESENT" />
            </intent-filter>
        </receiver>

但是没有成功...

我的申请class

public class AppApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();

        System.out.println("vrum");
        Parse.initialize(this, "...", "..");
        PushService.setDefaultPushCallback(this, HomeActivity.class);
        ParseInstallation.getCurrentInstallation().saveInBackground();

    }

当我点击通知时,我会进入主页Activity...如果我删除那条线,结果也是一样

 PushService.setDefaultPushCallback(this, HomeActivity.class);
 public class ParseCustomBroadcastReceiver extends ParsePushBroadcastReceiver {

        @Override
        public void onReceive(Context context, Intent intent) {
            try {

    // Sample code
                JSONObject json = new JSONObject(intent.getExtras().getString("com.parse.Data"));
                final String notificationTitle = json.getString("title").toString();
                final String notificationContent = json.getString("alert").toString();
                final String uri = json.getString("uri");

    //Create a taskstack builder - this is just sample snippet to give an idea
                Intent resultIntent = null;
                TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
resultIntent = new Intent(context, NotificationOpenActivity.class);
stackBuilder.addParentStack(NotificationOpenActivity.class);
stackBuilder.addNextIntent(resultIntent);
            PendingIntent resultPendingIntent =
                    stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);


                // Customize your notification
                NotificationCompat.Builder builder =
                        new NotificationCompat.Builder(context)
                                .setSmallIcon(R.mipmap.ic_notification_icon)
                                .setContentTitle(notificationTitle)
                                .setContentText(notificationContent)
                                .setGroup(GROUP_SHORTR_NOTIFS)
                                .setContentIntent(resultPendingIntent)
                                .setAutoCancel(true)
                                .setVisibility(Notification.VISIBILITY_PUBLIC)
                                .setDefaults(Notification.DEFAULT_VIBRATE)
                                .setStyle(new NotificationCompat.BigTextStyle()
                                        .bigText(notificationContent));

                int mNotificationId = 001;
                NotificationManager mNotifyMgr =
                        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
                mNotifyMgr.notify(mNotificationId, builder.build());


            } catch (JSONException e) {
                Log.d(TAG, e.getMessage());
            }

        }
    }

在清单中添加以下内容。

<receiver
            android:name=".receivers.ParseCustomBroadcastReceiver"
            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>

基本上,对于从您的问题中提取的清单编辑,只需编辑 android:name 属性。

希望对您有所帮助!