我怎样才能获得的数据或标题自收到通知? [英] How can I get data or title from receiving notifications?

查看:145
本文介绍了我怎样才能获得的数据或标题自收到通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建简单的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>

我不知道你的意思是你有问题的主要活动MyCustomReceiver班,在您的评论给@ kingspeech的答案。

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(上下文,意图)

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天全站免登陆