My application used Parse to push notification to multiple devices. But only one devices can receive that notification. I don't know why? Please help me. Here're some code :
AppController:
// Add your initialization code here
Parse.initialize(this, getString(R.string.parse_app_id), getString(R.string.parse_client_key));
ParseInstallation.getCurrentInstallation().saveInBackground();
ParsePush.subscribeInBackground("RadaBikeSp", new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
Log.d("Success", "successfully subscribed to the broadcast channel.");
} else {
Log.e("Fail", "failed to subscribe for push", e);
}
}
});
in Manifest:
<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="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<permission
android:name="thsoft.com.sosme.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="thsoft.com.sosme.permission.C2D_MESSAGE" />
<application
android:name=".services.AppController"
android:allowBackup="true"
android:fullBackupContent="true"
android:hardwareAccelerated="true"
android:icon="#drawable/iconapp"
android:label="#string/app_name"
android:largeHeap="true"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<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" />
<service android:name="com.parse.PushService" />
<receiver
android:name="com.parse.ParsePushBroadcastReceiver"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
<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="thsoft.com.sosme" />
</intent-filter>
</receiver>
<meta-data
android:name="com.parse.push.notification_icon"
android:resource="#drawable/iconapp" />
Thank in advance!
Your app needs to access to internet for using parse push notification.
please add this permission to your manifest :
<uses-permission android:name="android.permission.INTERNET" />
You have to exclude the GCM registration key from your fullBackupContent like here: https://github.com/googlesamples/android-AutoBackupForApps
Related
My code is as below
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.aaa"
android:versionCode="2027"
android:versionName="5.1.5" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="18" />
<uses-permission
android:name="android.permission.GET_TASKS"
android:protectionLevel="normal" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_OWNER_DATA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<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="com.aaa.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.aaa.permission.C2D_MESSAGE" />
<application
android:name="com.aaa.application.SalesEnablementApplication"
android:allowBackup="true"
android:icon="#drawable/ic_app_icon_new"
android:label="#string/app_name"
tools:replace="android:label"
android:largeHeap="true"
android:theme="#style/AppTheme" >
<meta-data
android:name="com.parse.APPLICATION_ID"
android:value="#string/application_id_stage" />
<meta-data
android:name="com.parse.CLIENT_KEY"
android:value="#string/client_key_stage" />
<receiver
android:name="com.xxx.util.NetworkStateReceiver"
android:enabled="false"
android:label="NetworkStateReceiver" >
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
</receiver>
.
.
.
<receiver android:name="com.aaa.pushNotification.PushBroadcastReceiver" >
<intent-filter>
<action android:name="com.aaa.Notification_ACTION" />
</intent-filter>
<!-- <category android:name="android.intent.category.DEFAULT" /> -->
</receiver>
<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.aaa.receiver.CustomParsePushBroadcastReceiver"
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.aaa" />
</intent-filter>
</receiver>
<receiver
android:name="com.aaa.receiver.MyReceiver"
android:exported="false" >
<intent-filter>
<action android:name="com.parse.starter.UPDATE_STATUS" />
<action android:name="com.aaa.UPDATE_STATUS" />
<!--
<action android:name="com.push.intent.RECEIVE" />
<action android:name="com.push.intent.DELETE" />
<action android:name="com.push.intent.OPEN" />
-->
</intent-filter>
</receiver>
<!--
<receiver
android:name="com.aaa.receiver.MyReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.aaa" />
</intent-filter>
</receiver>
-->
</application>
</manifest>
My Application Class:
public void onCreate() {
super.onCreate();
// Enable Local Datastore.
Parse.enableLocalDatastore(this);
// Init Parse App after checking the current environment
Parse.initialize(this);
/*if(Environment.ENV.equalsIgnoreCase(Environment.ENV_STAGE)){
Parse.initialize(this, getResources().getString(R.string.application_id_stage), getResources().getString(R.string.client_key_stage));
}else{
Parse.initialize(this, getResources().getString(R.string.application_id_prod), getResources().getString(R.string.client_key_prod));
}*/
ParseInstallation.getCurrentInstallation().saveInBackground();
ParseACL defaultACL = new ParseACL();
defaultACL.setPublicReadAccess(true);
defaultACL.setPublicWriteAccess(true);
ParseACL.setDefaultACL(defaultACL, true);
// used to store temp objects
dataStore = new DataStore();
eventCaptureHandler = new EventCaptureHandler(this);
}
I am using parse SDK version 1.13.0.
Testing on Android 6.0.1 (Sony Xperia Z2).
I try to send push message from the Parse Dashboard. I do not receive the notification sent. I noticed that DeviceType and pushType, in the Installation table, is set to (Undefined).
I'm using parse for sending notifications .I wrote this code and it works find on emulator but I get the notifications on phones . this is the manifest:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<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:name="mypackagename.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.parse.starter.permission.C2D_MESSAGE" />
<uses-permission android:name="mypackagename.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:name="mypackagename.ParseApplication"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat.Light">
<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" />
<!-- IMPORTANT: Change "com.parse.tutorials.pushnotifications" to match your app's package name. -->
<category android:name="mypackagename.MessageAll" />
</intent-filter>
</receiver>
<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="mypackagename.MessageAll"
android:exported="false">
<intent-filter>
<action android:name="mypackagename.MessageAll" />
<action android:name="MessageAll" />
</intent-filter>
</receiver>
for mypackagename I use my package name .
in the parseApplication :
import com.parse.Parse;
import com.parse.PushService;
public class ParseApplication extends android.app.Application {
public ParseApplication() {
}
#Override
public void onCreate() {
super.onCreate();
Parse.initialize(this, "9OaXWT76IDHlZiwQVaGwECw7LISflGmLmDJf0VTa", "0JcMfXSQPn2oJpH6x8qR2gJhG41U17nVOXOWmIIK");
PushService.setDefaultPushCallback(this, FistActiivty.class);
}
}
I've changed these two values with new codes from parse keys .
when I debug it on the phone ,I get this message:
com parse PushService: Tried to use push, but this app is not configured for push due to: Push is not configured for this app because the app manifest is missing required declarations. Please add the following declarations to your app manifest to support either GCM or PPNS for push (or both). To enable GCM support, please make sure that these permissions are declared as children of the root <manifest> element:
what is wrong ? I don't get it .
I cannot send pushnotification from my application via Parse. I checked every settings:
Manifest has been set correctly (permissions, package names)
Parse has been initialized (with right keys), and localdatastore enabled
All device use the same pushnotification channel, and subscribed to it
On the Parse admin page, "Client push enabled" checked
After all of this, i want to send a pushnotification, but i cannot do this. I started to debug this issue.
First of all, i checked that the push notification had been sent or not.
ParsePush push = new ParsePush();
push.setChannel(channel);
push.setMessage(message);
push.sendInBackground(new SendCallback() {
#Override
public void done(ParseException e) {
Log.d("SEND PUSH", (e == null) ? "SUCCESSFULL": "FAILED");
}
});
But this method returns with "SUCCESSFULL". So it has to be good. But on the Parse admin page and on the devices it is not showing.
I was curious, that i can receive push notifications, so i sent a pushnotification to my channel, from the parse admin page. And that worked.
So i think, the problem is in the sending method or in the manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="conversation.laszlomagyar.hu" >
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<!-- parse permissions -->
<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="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="conversation.laszlomagyar.hu.permission.C2D_MESSAGE" />
<permission android:protectionLevel="signature"
android:name="conversation.laszlomagyar.hu.permission.C2D_MESSAGE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:name=".ApplicationObject">
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data android:name="com.parse.push.notification_icon"
android:resource="#mipmap/ic_launcher"/>
<activity
android:name=".ui.StarterActivity"
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>
<activity android:name=".ui.Activity"
android:label="#string/rooms"
android:screenOrientation="portrait"/>
<activity android:name=".ui.Activitytwo"
android:label="#string/app_name"
android:screenOrientation="portrait"/>
<activity android:name=".ui.Activitythree"
android:label="#string/create_room"
android:screenOrientation="portrait" />
<!-- parse stuffs -->
<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.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="conversation.laszlomagyar.hu" />
</intent-filter>
</receiver>
</application>
I am attempting to set up push notifications for my application. I have followed the appropriate quickstart guide and the tutorial and have, as far as I can tell, set everything up correctly, but when I run the app I get the following LogCat error:
E/com.parse.ManifestInfo(17775): Cannot use GCM for push because the app manifest is missing some required declarations. Please make sure that these permissions are declared as children of the root <manifest> element:
E/com.parse.ManifestInfo(17775): <uses-permission android:name="android.permission.INTERNET" />
E/com.parse.ManifestInfo(17775): <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
E/com.parse.ManifestInfo(17775): <uses-permission android:name="android.permission.VIBRATE" />
E/com.parse.ManifestInfo(17775): <uses-permission android:name="android.permission.WAKE_LOCK" />
E/com.parse.ManifestInfo(17775): <uses-permission android:name="android.permission.GET_ACCOUNTS" />
E/com.parse.ManifestInfo(17775): <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
E/com.parse.ManifestInfo(17775): <permission android:name="com.example.myapp.permission.C2D_MESSAGE" android:protectionLevel="signature" />
E/com.parse.ManifestInfo(17775): <uses-permission android:name="com.example.myapp.permission.C2D_MESSAGE" />
E/com.parse.ManifestInfo(17775): Also, please make sure that these services and broadcast receivers are declared as children of the <application> element:
E/com.parse.ManifestInfo(17775): <service android:name="com.parse.PushService" />
E/com.parse.ManifestInfo(17775): <receiver android:name="com.parse.GcmBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND">
E/com.parse.ManifestInfo(17775): <intent-filter>
E/com.parse.ManifestInfo(17775): <action android:name="com.google.android.c2dm.intent.RECEIVE" />
E/com.parse.ManifestInfo(17775): <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
E/com.parse.ManifestInfo(17775): <category android:name="com.example.myapp" />
E/com.parse.ManifestInfo(17775): </intent-filter>
E/com.parse.ManifestInfo(17775): </receiver>
Here's the relevant excerpt from my manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<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" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<permission android:name="com.example.myapp.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.myapp.permission.C2D_MESSAGE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<!-- activities excluded to be concise -->
<service android:name="com.parse.PushService" />
<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.myapp" />
</intent-filter>
</receiver>
<receiver android:name="com.parse.ParsePushBroadcastReceiver" >
<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.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>
<meta-data
android:name="com.parse.push.notification_icon"
android:resource="#drawable/push_icon" />
</application>
</manifest>
I've double and triple checked and it seems like I have everything that the error is saying I need. Is there something obvious that I'm missing here?
Other possibly relevant information:
My launcher activity
public class StartActivity extends ActionBarActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Parse.initialize(this, "REDACTED", "REDACTED");
ParsePush.subscribeInBackground("");
ParseUser user = ParseUser.getCurrentUser();
Intent i;
if (user == null) {
i = new Intent(this, LogInActivity.class);
} else {
i = new Intent(this, MainActivity.class);
}
startActivity(i);
finish();
}
}
There is not currently anything related to pushes in any of my other classes. One possibility I haven't tested yet is that my lack of a ParsePushBroadcastReceiver subclass is causing a problem, but based on the documentation in the Parse API, this doesn't seem to be necessary for the basic push service.
My full manifest, in case it's needed:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<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" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<permission android:name="com.example.myapp.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.myapp.permission.C2D_MESSAGE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".LogInActivity"
android:label="#string/app_name" >
</activity>
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
</activity>
<activity
android:name=".ChatActivity"
android:label="#string/app_name"
android:windowSoftInputMode="stateHidden" >
</activity>
<activity
android:name=".StartActivity"
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.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.myapp" />
</intent-filter>
</receiver>
<receiver android:name="com.parse.ParsePushBroadcastReceiver" >
<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.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>
<meta-data
android:name="com.parse.push.notification_icon"
android:resource="#drawable/push_icon" />
</application>
</manifest>
I'll happily provide any more information that's requested, this is all I could think of. Thanks in advance for any help.
Welp. After all the time I spent on this, it turns out I was just another victim of a typo. Although, I don't actually know what the typo was... I ended up just copy+pasting the error log into my manifest and erasing the timestamp (leaving just the suggested code) and using that to replace the relevant lines. I still can't see a difference, but it's working now. I feel pretty ridiculous.
I am using Parse to send notifications from device to device. I've set up a broadcast receiver to generate a custom notification when it receives intent from a notification coming in from Parse. The problem is that the broadcast receiver on the emulator works just fine but on the device it just does not receive the intent.
AndroidManifest
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<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:protectionLevel="signature"
android:name="org.example.app.permission.C2D_MESSAGE" />
<uses-permission android:name="com.example.app.permission.C2D_MESSAGE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.Holo.NoActionBar.Fullscreen" >
<activity
android:name="org.example.app.MainActivity"
android:label="#string/app_name"
android:launchMode="singleInstance">
<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" />
<!--
IMPORTANT: Change "com.parse.starter" to match your app's package name.
-->
<category android:name="org.example.app" />
</intent-filter>
</receiver>
<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="org.example.app.Receiver"
android:priority="999999999"
android:exported="true"
android:enabled="true">
<intent-filter android:priority="999999999">
<action android:name="org.example.app.A_CUSTOM_INTENT"/>
</intent-filter>
</receiver>
</application>
An this is the onClick that calls for a Parse notification
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(context, "this is shown" , Toast.LENGTH_LONG).show();
try {
ParseQuery<ParseInstallation> query = ParseInstallation.getQuery();
JSONObject data = new JSONObject("{\"action\": \"org.example.app.A_CUSTOM_INTENT\"}");
ParsePush androidPush = new ParsePush();
androidPush.setData(data);
androidPush.setExpirationTimeInterval(120);
androidPush.setQuery(query);
androidPush.sendInBackground();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
As I've said, this works on an emulator just fine and the device does receive notifications from the Parse service but does not respond to intent. Thank you for your help.
Looks like you have an error here :
<permission android:protectionLevel="signature"
android:name="org.example.app.permission.C2D_MESSAGE" />
<uses-permission android:name="com.example.app.permission.C2D_MESSAGE" />
I'm assuming the correct value is org.example.app (based on the rest of the manifest), so it should be :
<permission android:protectionLevel="signature"
android:name="org.example.app.permission.C2D_MESSAGE" />
<uses-permission android:name="org.example.app.permission.C2D_MESSAGE" />
The reason it works on the emulator and not on the device could be that the device has an older Android version. This error affects only 2.x Android devices.