使用解析

时间:2016-08-01 23:14:55

标签: android parse-platform notifications push

我在nodechef.com中使用解析1.13.0我尝试设置我的应用程序发送通知但我遇到了一些问题。

这是我的清单:

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.my.path" >
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.my.path.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.my.path.permission.C2D_MESSAGE" />

<application
    android:name=".MainApplication"
    android:allowBackup="true"
    android:fullBackupContent="true"
    android:icon="@drawable/logo"
    android:label="@string/app_name"
    android:theme="@style/hsfTheme">

    <meta-data
        android:name="com.parse.APPLICATION_ID"
        android:value="@string/parse_app_id" />
    <meta-data
        android:name="com.parse.CLIENT_KEY"
        android:value="@string/parse_client_key" />

    <meta-data
        android:name="com.parse.push.notification_icon"
        android:resource="@drawable/logo" />

    <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.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.my.path" />
        </intent-filter>
    </receiver>

    <!-- activity main. -->
    <activity
        android:name=".A0"
        android:configChanges="keyboardHidden|screenLayout|orientation"
        android:immersive="true"
        android:screenOrientation="portrait"
        android:theme="@style/hsfTheme.NoActionBar" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity android:name=".A1" />
    <activity android:name=".A2" />
    <activity android:name=".A3" />
    <activity android:name=".utils.A4" />

    <!-- Include the AdActivity configChanges and theme. -->
    <activity
        android:name="com.google.android.gms.ads.AdActivity"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
        android:theme="@android:style/Theme.Translucent" />
</application>

在我的应用程序类中我有:ParseInstallation.getCurrentInstallation()。saveInBackground();

  • _Installation class
  • 中的DeviceToken为空
  • 推送不工作

我需要的是从我的应用程序发送推送通知,在某些操作中,我想通知所有用户或使用安装渠道的一些用户。不在乎我是否会使用“解析推”或gcm,只需要一种简单的方法从app发送推送通知。

修改 从解析仪表板推送现在正在工作,但我无法从客户端发送推送通知。我尝试了推送并获得“未授权:启用主密钥”。那么我需要做什么?

编辑2 我创建了一个云代码,但它看起来不起作用从 request.params 获取值:

Parse.Cloud.define("sendPush", function(request,response) {
var _locale = "en-US";//request.params.locale;
var _message = "test";//request.params.message;
var query = new Parse.Query(Parse.Installation);
query.equalTo("localeIdentifier", _locale);
Parse.Push.send({
        data:   {
            alert: _message,
        badge: "Increment",
            sound: "default"
        },
        where: query
    }, {
      useMasterKey: true
    })
    .then(function() {
      response.success("Push Sent!");
    }, function(error) {
      response.error("Error while trying to send push " + error.message);
    });
});

编辑3

HashMap<String,String> map = new HashMap<String, String>();
map.put("locale","en-US");
map.put("message","Text added");

ParseCloud.callFunctionInBackground("sendPush",map, new FunctionCallback<Object>() {

    @Override
    public void done(Object object, ParseException e) {
        // toast done
    }
});

1 个答案:

答案 0 :(得分:1)

调查之后我注意到,为了发送推送,你必须创建云代码功能并使用你的主密钥(通过发送 userMasterKey = true 参数发送推送功能。 我在here中描述了我的答案,所以请完成这些步骤,它应该适合你。