【问题标题】:Extracting text from Push Notification using Parse.com使用 Parse.com 从推送通知中提取文本
【发布时间】:2014-08-11 21:18:14
【问题描述】:

我正在尝试制作一个接收器以从 Parse.com 提供支持的推送通知中提取文本,我收到了通知,但看起来我的 BroadcastReceiver 没有被调用,因为 Log.d 没有记录

我的 MainActivity.java onCreate()

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Parse.initialize(this, "-", "-"); //removed keys for question
    PushService.setDefaultPushCallback(this, MainActivity.class);
    ParseAnalytics.trackAppOpened(getIntent());   
}

我的 Manifest.xml 接收器

<service android:name="com.parse.PushService" />

    <receiver android:name="com.parse.ParseBroadcastReceiver" >
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.USER_PRESENT" />
        </intent-filter>
    </receiver>
    <receiver
        android:name="com.example.parsepushnotificationreceiver.MyCustomReceiver"
        android:exported="false" >
        <intent-filter>
            <action android:name="com.example.parsepushnotificationreceiver.UPDATE_STATUS" />
        </intent-filter>
    </receiver>
    <receiver
        android:name="com.parse.GcmBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

            <category android:name="com.example.parsepushnotificationreceiver" />
        </intent-filter>
    </receiver>

我的 BroadcastReceiver 类

@Override
public void onReceive(Context context, Intent intent) {
    try {
        String action = intent.getAction();
        String channel = intent.getExtras().getString("com.parse.Channel");
        JSONObject json = new JSONObject(intent.getExtras().getString(
                "com.parse.Data"));

        Log.d(TAG, "got action " + action + " on channel " + channel
                + " with:");
        Iterator itr = json.keys();
        while (itr.hasNext()) {
            String key = (String) itr.next();
            Log.d(TAG, "..." + key + " => " + json.getString(key));
        }
    } catch (JSONException e) {
        Log.d(TAG, "JSONException: " + e.getMessage());
    }
}
}

我的包裹是

package com.example.parsepushnotificationreceiver;

谢谢,

解决方案:

得到它的工作,这个想法是在 json 对象被自己发送,模板 {"action": "com.example.parsepushnotificationreceiver.UPDATE_STATUS", “名称”:“沃恩”, "newsItem": "人咬狗"}

【问题讨论】:

  • 您可能不应该在您的问题中发布您的个人 PARSE_APPLICATION_ID 和 PARSE_CLIENT_KEY...
  • @LarryMcKenzie 没关系,它是一个测试应用程序,但我删除了它们,谢谢,有什么解决方案吗?谢谢
  • 我从未使用过它,但我正在阅读文档。
  • @LarryMcKenzie 太好了,谢谢你的帮助 :)
  • 让它工作了,这个想法是在 json 对象中被它自己发送,模板 {"action": "com.example.parsepushnotificationreceiver.UPDATE_STATUS", "name": "Vaughn", "newsItem ": "人咬狗"}

标签: android text push-notification broadcastreceiver parse-platform


【解决方案1】:

解决方案:

得到它的工作,这个想法是在 json 对象被自己发送,模板 {“action”:“com.example.parsepushnotificationreceiver.UPDATE_STATUS”,“name”:“Vaughn”,“newsItem”:“Man beats狗”}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多