如何通过接收通知获取数据或标题? [英] How can I get data or title from receiving notifications?

查看:18
本文介绍了如何通过接收通知获取数据或标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了简单的ParseStarterProject"作为 parse.com 项目的默认值.有用.我通过 setchannel 方法成功地将通知从一台设备发送到另一台设备.

I create simple "ParseStarterProject" as default of parse.com project. It works. I send notification from one device to other device successfully via setchannel method.

但问题是我不使用接收器类(我不知道如何使用它)所以当通知出现时我需要获取它的消息?有可能的?或者如果我使用集合数据,我可以获得它的数据吗?

But the problem is I do not use receiver class(I do not know how can I use that) so when a notification comes I need to get its message ? it is possible? or if I use set data can I get its data ?

ParsePush push = new ParsePush();
String yourMessage = "Selam from LG G2";//I want to get this message from other device?
push.setChannel("device2");
push.setMessage(yourMessage);
//push.setData("exampledata"); if I use this can I get this data from other device?
push.sendInBackground();

我的清单文件:

    <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.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" />

        <!--
          IMPORTANT: Change "com.parse.starter" to match your app's package name.
        -->
        <category android:name="com.parse.starter" />
      </intent-filter>
</receiver>

提前致谢

推荐答案

创建一个扩展BroadcastReceiver的类,这里我们称之为MyCustomReceiver.在您的清单中声明此接收器的用法:

Create a class that extends BroadcastReceiver, here we call it MyCustomReceiver. Declare the usage of this receiver in your manifest:

<receiver android:name="com.example.MyCustomReceiver" android:exported="false">
  <intent-filter>
    <action android:name="com.example.UPDATE_STATUS" />
  </intent-filter>
</receiver>

在您对@kingspeech 的回答的评论中,我不确定您所说的主要活动的 MyCustomReceiver 类"是什么意思.

I'm not sure what you mean by you have problems with "MyCustomReceiver class on the main activity", in your comment to @kingspeech's answer.

在最坏的情况下,您可以创建自己的接收器来扩展 ParseBroadcastReceiver(并在清单中引用扩展类).然后它应该在默认情况下工作,但您将能够连接到 onReceive(Context, Intent)

In the worst case, you can create your own Receiver which extends the ParseBroadcastReceiver (and reference the extended class in the manifest). Then it should work by default, but you'll be able to hook into onReceive(Context, Intent)

这篇关于如何通过接收通知获取数据或标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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