自定义 Parse 推送通知 - Android

Customise Parse push notification - Android

我是 Android 使用 Parse 推送通知的新手。我已经成功地将解析推送通知集成到我的项目中并进行了测试。它工作正常,但我有几个与此推送通知服务相关的问题,我无法在 Parse 文档中找到这些问题。

  1. 如何自定义推送通知的声音?
  2. 如何在不使用解析控制台的情况下从设备本身发送推送通知?
  3. 为了执行上述操作我必须保存的唯一 ID 是什么?

提前致谢。

How do I customise the push notification's sound?

默认情况下,当收到推送通知时,会调用 AndroidManifest.xml 中指定的 BroadcastReceiver 以及指定 <action android:name="com.parse.push.intent.RECEIVE" /> 的 intentfilter。

Parse.com 提供了一个 BroadCastReceiver com.parse.ParsePushBroadcastReceiver,它只是发出设备的默认通知声音。它没有用于特定通知声音的代码,如果你想通过解析更改推送的通知声音,你必须使用上面指定的 intentfilter 实现一个新的 BroadCastReceiver 并具有以下自定义声音代码(它只是部分演示代码):

Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
builder.setSound(alarmSound);

How do I send a push notification from the device itself, without using the parse console?

推送通知可以从一个设备发送到另一个设备或从控制台发送到设备。安装在注册推送通知的设备上的每个 Parse 应用程序都有一个关联的 Installation 对象。 Installation 对象是您存储定位推送通知所需的所有数据的地方。现在会有很多应用程序用户,您可能希望针对特定用户,例如,应用程序在第一次安装应用程序时收集用户名并将其设置在安装对象中,如下所示:

 ParseInstallation installation = ParseInstallation.getCurrentInstallation();
  installation.put("userName", "ranjith");  //mobile 1
  installation.saveInBackground();

现在要向用户名 "ranjith" 发送通知,您需要创建一个具有条件 -username=ranjithParseQuery 对象,如下所示,这将向用户名 "ranjith".

发送推送通知
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
    ParseQuery pushQuery = ParseInstallation.getQuery();//mobile2
    pushQuery.whereEqualTo("userName", "ranjith");
    ParsePush push = new ParsePush();
    push.setQuery(pushQuery); // Set our Installation query
    push.setMessage("My first notification");

What is the unique Id that I must save in order to perform the above?

这些是 parse 安装对象中存在的 2 个唯一 ID,它们是由 parse 生成的,您无需担心,要针对特定​​用户,您可以在安装中添加一个唯一的 id/username 字段上面指定的对象,

  • installationId:Parse 使用的设备的唯一 ID(只读)。
  • appIdentifier:此安装客户端的唯一标识符 应用。 Android 不支持此参数。(只读)