Push notification is not working using parse.com android? - android

I have created simple push notification app using parse.com.
devices registered successfully on parse.com but when i try to send push notification through parse.com no notification have come.
AndroidMainifest.xml Code:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<permission android:protectionLevel="signature"
android:name="com.parse.starter.permission.C2D_MESSAGE" />
<uses-permission android:name="com.parse.starter.permission.C2D_MESSAGE" />
service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParsePushBroadcastReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</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.parse.starter" />
</intent-filter>
</receiver>
<meta-data
android:name="com.parse.APPLICATION_ID"
android:value="" />
<meta-data
android:name="com.parse.CLIENT_KEY"
android:value="" />
Reciever Code:
public class Receiver extends ParsePushBroadcastReceiver {
private Intent parseIntent;
public Receiver() {
super();
}
#Override
protected void onPushReceive(Context context, Intent intent) {
super.onPushReceive(context, intent);
if (intent == null)
return;
try {
JSONObject json = new JSONObject(intent.getExtras().getString("com.parse.Data"));
parseIntent = intent;
} catch (JSONException e) {
Log.d("PushJsonException", "" + e.getMessage());
}
}
}
MainActivity Code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Parse.initialize(this);
ParseInstallation.getCurrentInstallation().saveInBackground();
}
private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
// Call Methods to Update Your Stuff
}
};
#Override
protected void onResume() {
super.onResume();
LocalBroadcastManager.getInstance(this).registerReceiver(mBroadcastReceiver, new IntentFilter("com.example.harrypotter.pushnotificationdemo"));
}
#Override
protected void onPause() {
super.onPause();
LocalBroadcastManager.getInstance(this).unregisterReceiver(mBroadcastReceiver);
}
Application Class :
public class ParseApp extends Application {
#Override
public void onCreate() {
super.onCreate();
Parse.initialize(this);
ParseInstallation.getCurrentInstallation().saveInBackground();
}
}

You have not changed the Category attribute in your Manifest file:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<permission android:protectionLevel="signature"
android:name="com.parse.starter.permission.C2D_MESSAGE" />
<uses-permission android:name="com.parse.starter.permission.C2D_MESSAGE" />
service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParsePushBroadcastReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
IMPORTANT: Change "com.parse.starter.permission.C2D_MESSAGE" in the lines below
to match your app's package name + ".permission.C2D_MESSAGE".
<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="YOUR PACKAGE NAME" />
</intent-filter>
</receiver>
<meta-data
android:name="com.parse.APPLICATION_ID"
android:value="" />
<meta-data
android:name="com.parse.CLIENT_KEY"
android:value="" />

Parse.com Hosted Service is fully retiring on January 28, 2017. If you have an existing application, refer to this link and create your own push notification server. Parse release a database migration tool that lets you migrate data from your Parse app to any MongoDB database.
For More Information Check The LInk

Related

Parse-Android ; Unable to receive 'action' in custom ParseBroadcastReceiver

Im sending a push message with a custom action but in the onPushReceive the action that I get is com.parse.push.intent.RECEIVE instead of com.hellboy.beat.STATUS_DONE
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hellboy.beat"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="23" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<!-- permission required to use Alarm Manager -->
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
<!-- permission required for Notification -->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<!-- permission required to Send SMS -->
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<!-- permission required to get Location & Number -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- permission required to Vibrate -->
<uses-permission android:name="android.permission.VIBRATE" />
<!-- permission required to use Parse -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- permission required to use Parse Push -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission
android:name="com.parse.starter.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.hellboy.beat.permission.C2D_MESSAGE" />
<application
android:name="com.hellboy.beat.Application"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.hellboy.beat.main.Activity_main"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.hellboy.beat.login.Activity_login" />
<activity android:name="com.hellboy.beat.requests.Activity_requests" />
<activity android:name="com.hellboy.beat.settings.Activity_settings" />
<!-- Register the Notification Receiver -->
<service android:name="com.parse.PushService" />
<!-- Regular Push Notification -->
<receiver android:name="com.parse.ParseBroadcastReceiver" />
<!-- Our Reciver -->
<receiver
android:name="com.hellboy.beat.PushRec"
android:exported="false" >
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.hellboy.beat.STATUS_DONE" />
<action android:name="com.parse.push.intent.OPEN" />
</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.hellboy.beat" />
</intent-filter>
</receiver>
</application>
</manifest>
PushRec.java
public class PushRec extends ParsePushBroadcastReceiver
{
private static final String TAG = "BEAT_PUSHREC";
Context context;
#Override
public void onPushReceive(Context context, Intent intent)
{
this.context = context;
Log.i(TAG, "Receiver");
if (intent == null)
{
Log.i(TAG, "Receiver intent null");
}else
{
Log.i(TAG, "Receiver intent not null");
String action = intent.getAction();
Log.i(TAG, "got action " + action );
if (action.equals("com.hellboy.beat.STATUS_DONE"))
{
//DOES NOT COME OVER HERE
}
}
}
}
Sending-Push:
ParseQuery<ParseInstallation> pushQuery = ParseInstallation.getQuery();
pushQuery.whereMatchesQuery("user", subscriberQuery);
JSONObject obj=null;
obj =new JSONObject();
try
{
obj.put("action","com.hellboy.beat.STATUS_DONE");
obj.put("statusdone_message" , message);
} catch (JSONException e1) {
e1.printStackTrace();
}
//TODO move this to the 'cloud'
ParsePush pPush = new ParsePush();
pPush.setQuery(pushQuery);
pPush.setData(obj);
pPush.sendInBackground();
NOTE: My understanding is I'm making a mistake in the Manfiest since the notification arrives, but the wrong action is called
You can override onReceive method to dispatch your custom action.
#Override
public void onReceive(Context context, Intent intent) {
String intentAction = intent.getAction();
switch (intentAction) {
case "com.hellboy.beat.STATUS_DONE":
onPushReceive(context, intent);
break;
case ACTION_PUSH_DELETE:
onPushDismiss(context, intent);
break;
case ACTION_PUSH_OPEN:
onPushOpen(context, intent);
break;
}
}
https://github.com/ParsePlatform/Parse-SDK-Android/blob/master/Parse/src/main/java/com/parse/ParsePushBroadcastReceiver.java
The error was in the Manifest; ParseBroadcastReceiver should be ParsePushBroadcastReceiver
Snippet:
<receiver
android:name="com.parse.ParsePushBroadcastReceiver"
android:exported="false" >
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
<receiver android:name="com.hellboy.beat.PushRec" >
<intent-filter>
<action android:name="com.hellboy.beat.STATUS_DONE" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
And remove this from the Manifest:
<!-- Regular Push Notification -->
<!-- REMOVE THIS -->
<receiver android:name="com.parse.ParseBroadcastReceiver" />
Also in the Receiver:
public class PushRec extends ParsePushBroadcastReceiver
{
}
becomes
public class PushRec extends BroadcastReceiver
{
}

Parse Push Notification for android not working

I have looked into many questions but i didn't get any push notifications.
I have added all the permissions and have simple receiver. When i debug it shows the device token to be null. In parse the device is detected and the notification is marked to be sent but not received in my device.
I am sharing the code
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
Parse.initialize(this, "", "");
}
catch (Exception e){
e.printStackTrace();
}
ParseInstallation.getCurrentInstallation().saveInBackground();
ParseInstallation.getCurrentInstallation().saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
Log.e("Tag 1", e == null ? "Succeed to register the app" : "Failed to register the app", e);
String deviceToken = (String) ParseInstallation.getCurrentInstallation().get("deviceToken");
Log.d("Tag 2", "Device token: " + deviceToken);
}
});
Manifest file
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.arpan.push_notifivations">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<permission android:protectionLevel="signature"
android:name="com.example.arpan.push_notifivations.permission.C2D_MESSAGE" />
<uses-permission android:name="com.example.arpan.push_notifivations.permission.C2D_MESSAGE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name="com.example.arpan.push_notifivations.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParsePushBroadcastReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</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.example.arpan.push_notifivations" />
</intent-filter>
</receiver>
</application>
</manifest>
The dependencies i added are
compile 'com.parse.bolts:bolts-android:1.+'
compile 'com.parse:parse-android:1.+'

Android Parse Push Notifications Not Working - Outdated Device

I just updated the latest Parse SDK (1.11.0) and now I'm not receiving push notifications. I am able to register successfully and can see on the parse site that that my "developer" channel has been subscribed but pushes never get sent and I get this error:
PPNS - Outdated device - The records on this installation are
outdated, the user might have uninstalled the app.
Can someone please take a look at my code and see if you notice anything incorrect?
public class LSIApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
Parse.initialize(this, "********", "********");
ParseInstallation.getCurrentInstallation().saveInBackground();
ParsePush.subscribeInBackground("developer", new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
Log.d("com.parse.push", "successfully subscribed to the broadcast channel.");
} else {
Log.e("com.parse.push", "failed to subscribe for push", e);
}
}
});
Parse.setLogLevel(Parse.LOG_LEVEL_VERBOSE);
}
}`
Android Manifest:
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission
android:name="${applicationId}.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="${applicationId}.maps.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:name="android.hardware.telephony" android:required="false" />
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>
<permission android:protectionLevel="signature"
android:name="${applicationId}.permission.C2D_MESSAGE" />
<uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<application android:name=".LSIApplication"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="********" />
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParsePushBroadcastReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
<receiver android:name=".startup.PushBroadcastReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
</application>
Note: The ${applicationId} is 'com.broker.schlisimobile.dev' and/or 'com.broker.schlisimobile' depending on whether it's a production or developer build.
Here is my custom PushBroadcastReceiver class:
public class PushBroadcastReceiver extends ParsePushBroadcastReceiver {
#Override
protected void onPushOpen(Context context, Intent intent) {
if ( storyJSONExists(intent) ) {
if (!DataController.getInstance().getCurrentUser().isGuestUser() ) {
Intent i = new Intent(context, PushLoadingActivity.class);
i.putExtras(intent.getExtras());
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
} else {
Intent i = new Intent(context, HomeActivity.class);
i.putExtra("promptForLogin", true);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(i);
}
} else {
Intent i = new Intent(context, HomeActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP);
i.putExtras(i);
context.startActivity(i);
}
}
private boolean storyJSONExists(Intent intent) {
try {
String jsonString = intent.getExtras().getString("com.parse.Data");
JSONObject json = new JSONObject(jsonString);
if ( json.has("postID") ) {
return true;
}
} catch (JSONException jsonE) {
jsonE.printStackTrace();
}
return false;
}
}
In your manifest.xml comment/delete below code,
<receiver android:name="com.parse.ParsePushBroadcastReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
then add below code in manifest.xml
<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="your_application_id" />
</intent-filter>
</receiver>
hope it works.

Android Studio: App does not receive push notifications from parse.com

I know that this question has been asked many times but i am still unable to get push notifications from parse.com
The push Notifications are being successfully sent from parse.com but my app does not receive them.
Most people have their problem resolved using this: I can't receive push notifications in app from Parse bt that doesnt work for me.
I also tried Android - Can not Receive Push from Parse.com.
Some people suggest changing names of packages, i did that and even made a new app but didnt help.
Note: i have imported parse-1.9.1.jar and bolts-android-1.2.0.jar
Here is my MainActivity
package com.example.user.parsetest;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import com.parse.Parse;
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Parse.initialize(this, "********", "********");
}
}
I tried adding custom PushReceiver as suggested in many answers
package com.example.user.parsetest;
import android.app.Activity;
import android.app.Notification;
import android.content.Context;
import android.content.Intent;
import com.parse.ParsePushBroadcastReceiver;
public class Receiver extends ParsePushBroadcastReceiver {
#Override
protected Notification getNotification(Context context, Intent intent) {
// TODO Auto-generated method stub
return super.getNotification(context, intent);
}
#Override
public void onPushOpen(Context context, Intent intent) {
Intent i = new Intent(context, MainActivity.class);
i.putExtras(intent.getExtras());
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
#Override
protected void onPushReceive(Context context, Intent intent) {
//here You can handle push before appearing into status e.g if you want to stop it.
super.onPushReceive(context, intent);
}
}
And the AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<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.example.user.parsetest.Receiver"
android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</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.example.user.parsetest" />
</intent-filter>
</receiver>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<meta-data android:name="com.parse.push.notification_icon"
android:resource="#drawable/ic_launcher"/>
<!--
IMPORTANT: Change "com.parse.starter.permission.C2D_MESSAGE" in the lines below
to match your app's package name + ".permission.C2D_MESSAGE".
-->
<permission android:protectionLevel="signature"
android:name="com.example.user.parsetest.permission.C2D_MESSAGE" />
<uses-permission android:name="com.example.user.parsetest.permission.C2D_MESSAGE" />
</application>
Unable to figure out the problem. pleaseeee help.
In your Application class just after the line for Parse.initialize(appkey,clientkey); just add the following line and it should work.
// Current installation object
ParseInstallation parseInstallation = ParseInstallation.getCurrentInstallation();
// Save the updated installation object
parseInstallation.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
MyLog.e(MainApplication.class.getSimpleName(), "Installation object saved "+((e!=null)?"failed":"successfully"));
}
});
Try downloading this project: https://www.dropbox.com/s/fpp22fi2o7c8vai/PushParse.zip?dl=0
It contains the 1.4.3 lib jar file. It's outdated but it's working.
I did, with a bit of tweaking, managed to update it to the latest library (1.9.2).
Watch out for errors that appear in your logcat. I got this: error setting up push notification using parse.com and android studio
If fixed by making sure my android manifest is very clean and organized. Follow the structure.
Here's my code for the updated parse library:
public class ParsePushNotification extends Application {
public ParsePushNotification() {
}
public void onCreate(){
super.onCreate();
Log.d("!!!", "This was called. Parse");
Parse.initialize(this, "paste your app id here", "paste your client id her");
// PushService.setDefaultPushCallback(this, LoginActivity.class);
// ParseInstallation.getCurrentInstallation().saveInBackground();
ParsePush.subscribeInBackground("", new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
Log.d("com.parse.push", "successfully subscribed to the broadcast channel.");
} else {
Log.e("com.parse.push", "failed to subscribe for push", e);
}
}
});
}
}
That class should be used here in your manifest:
<application
android:name="com.example.app.ParsePushNotification"
Here's my receiver class:
public class Receiver extends ParsePushBroadcastReceiver {
#Override
public void onPushOpen(Context context, Intent intent) {
Intent i = new Intent(context, LoginActivity.class);
i.putExtras(intent.getExtras());
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
Here's my manifest:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.example.app.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.app.permission.C2D_MESSAGE" />
<application
android:name="com.example.app.ParsePushNotification"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.NoTitle">
<meta-data
android:name="com.parse.push.notification_icon"
android:resource="#drawable/ic_launcher" />
<activity
android:name=".LoginActivity"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<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.example.app" />
</intent-filter>
</receiver>
<receiver android:name="com.example.app.Receiver"
android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
</application>
Good luck!

Why my custom receiver is not working?

I use parse.com api.
What my problem is :
When other client send push notification I did not receive anything on my broadcastreceiver.
My manifest
<service android:name="com.parse.PushService" />
<receiver
android:name=".MainActivity$MyReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="com.yy.xx.UPDATE_STATUS" />
</intent-filter>
</receiver>
<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" />
and my receiver in mainactivity is here:
public static class MyReceiver extends BroadcastReceiver {
public final String TAG = "MyReceiver";
#Override
public void onReceive(Context context, Intent intent) {
//this is not working,
try {
if (intent == null)
{
Log.d(TAG, "Receiver intent null");
}
else
{
String action = intent.getAction();
if (action.equals("com.yy.xx.UPDATE_STATUS"))
{
//....
}
}
} catch (JSONException e) {
Log.d(TAG, "JSONException: " + e.getMessage());
}
}
}
and my push notification send code is here:
JSONObject obj;
try {
obj =new JSONObject();
obj.put("action","com.yy.xx.UPDATE_STATUS");
obj.put("customdata","message...");
push_p = new ParsePush();
#SuppressWarnings("rawtypes")
ParseQuery query = ParseInstallation.getQuery();
// Notification for Android users
//query.whereEqualTo("deviceType", "android");
push_p.setQuery(query);
push_p.setData(obj);
push_p.setChannel("channel_111");
push_p.sendInBackground();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
I read parse.com api and tutorial but I do not understand what is the problem.
thanks in advance
Add all this declarations in manifest
<!-- PARSE SERVICE AND RECEIVERS -->
<service
android:name="com.parse.PushService"
android:enabled="true" />
<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:enabled="true"
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.example.app" />
</intent-filter>
</receiver>
<receiver android:name=".MainActivity$MyReceiver" >
<intent-filter>
<action android:name="com.example.update.UPDATE_STATUS" />
</intent-filter>
</receiver>
And add permissions
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="com.example.app.permission.C2D_MESSAGE" />
<permission
android:name="com.example.app.permission.C2D_MESSAGE"
android:protectionLevel="signature" />

Categories

Resources