Rodrigo Celebrone
Rodrigo Celebrone

Reputation: 346

Push notification from app using parse

i am using parse 1.13.0 in nodechef.com i tried setting my app to send notification but i getting some problems.

This is my Manifest:

<?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>

in my application class i have: ParseInstallation.getCurrentInstallation().saveInBackground();

All i need is send push notification from my app, in some actions i would like notify all users or some users using Installation channels. Don't care if i will use "parse push" or gcm, just need a simple way to send push notifications from app.

EDIT Push from parse-dashboard is working now, but i cant send push notification from client. I tried a push and got "unauthorized: enable master key". So what i need to do ?

EDIT 2 I created a cloud code but its looks not working get values from 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);
    });
});

EDIT 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
    }
});

Upvotes: 0

Views: 603

Answers (1)

Ran Hassid
Ran Hassid

Reputation: 2788

after investigate it a bit i noticed that in order to send push you must create cloud code function and use your master key (by sending userMasterKey=true parameter to the send push function. I describe my answer in here so please go through the steps and it should work for you.

Upvotes: 1

Related Questions