user2431174
user2431174

Reputation: 117

Parse.com how to enable client pushes

I'm targeting specific users when sending Parse notifications, using their email address. The send seems to work okay, but no message is received. What do I need to change to receive the message? In my Parse control panel it shows the attempted pushes but with the error message that "client-initiated pushes are not enabled". I really prefer initiating the pushes from the client. How do I enable that? I keep finding documentation that says to enable client pushes but I can't find how to do it.

Here is my setup:

        Parse.initialize(this, "...xxxAPP_ID", "...xxxCLIENT_KEY");
        PushService.setDefaultPushCallback(this, MainActivity.class);
        ParseInstallation.getCurrentInstallation().saveInBackground(); 
        ParseObject parseObject = new ParseObject("defaultObject");
        parseObject.put("email", sEmail)
        parseObject.saveInBackground(); 

The actually sending is done here:

    ParseQuery pQuery = ParseInstallation.getQuery(); 
    pQuery.whereEqualTo("email", ToUser); 
    ParsePush parsePush = new ParsePush();
    parsePush.setQuery(pQuery);
    parsePush.sendMessageInBackground("You have pictures waiting from " + sEmail, pQuery);

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:protectionLevel="signature" 
    android:name="com.pictureplay.permission.C2D_MESSAGE" />
<uses-permission android:name="com.pictureplay.permission.C2D_MESSAGE" />

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

Update: I have narrowed the problem down to push notifications being received unless the service is not running. I thought the Parse service was supposed to load when the phone restarts, but this is not the case here. Is there a way to get the Parse service for my app to load when the phone reboots?

Update2: The solution was to create a separate class (called "App" in my case) which initializes Parse. If the Parse service gets shut down when the app closes, the service restarts itself within minutes (automatically, I did no special setup for this) to be able to receive incoming push messages. These are the lines of code used in "App" onCreate:

    Parse.enableLocalDatastore(this);
    Parse.initialize(this, "data1", "data2");  //supply your own 
    PushService.setDefaultPushCallback(this, MainActivity.class);
    ParseInstallation.getCurrentInstallation().saveInBackground();

Upvotes: 1

Views: 2610

Answers (4)

Ziv Kesten
Ziv Kesten

Reputation: 1242

In the new Parse DashBoard: go to settings---> push ---> push notification settings---> client enabled push --- >set to "yes"

Upvotes: 0

Shayan_Aryan
Shayan_Aryan

Reputation: 2042

In your parse application Go to settings > Push > Client Push Enabled > set to Yes

Upvotes: 1

C--
C--

Reputation: 16558

The question Is there a way to get the Parse service for my app to load when the phone reboots? : Yes you can receive the BOOT_COMPLETE event if you have added the following permission on your manifest.

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>    

Upvotes: 0

user3653796
user3653796

Reputation: 158

Have you enable Sending notifications from Client. Its a setting in Parse.com. Go to settings ->App Permissions ->Allow client class creation. Set it to ON>

Upvotes: 6

Related Questions