I am developing an android application with push notification using GCM (step by step: http://developer.android.com/google/gcm/index.html) but not all devices getting notifications from GCM server.
I debugged it and I saw that my 3d-party server sends the message successfully.
When i send to my Galaxy-S4 device I get the notification but in my Galaxy-S2 i don't get.
AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.example.gcm.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.example.gcm.permission.C2D_MESSAGE" />
<receiver
android:name=".gcm.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.freco" />
</intent-filter>
</receiver>
<service android:name=".gcm.GcmIntentService" />
I think the other code its not necessary here because its works fine in Galaxy-S4.
What do you think is it ?
What's the package of your app, com.freco (as defined in the category of the broadcast receiver) or com.example.gcm (as defined in your permissions)?
You should use the package name of your app in both places. For some reason, this mismatch only causes problems in older Android versions. Newer versions work either way.
Looks like a copy paste error. In your manifest, change com.example to your actual package name
Related
As the title indicates I get a TIMEOUT exception when trying to get token using Google Cloud Messaging on API 10 emulator. I have added my google account on the device, checked that "Sync" is ON, also added the
<action android:name="com.google.android.c2dm.intent.REGISTRATION"/> in the manifest in the receiver and still cannot find out what is causing this:
11-25 17:35:00.896 29750-29774/com.example.alexis.myapplication W/InstanceID/Rpc: No response android.os.ConditionVariable#b667bc18
11-25 17:35:00.896 29750-29774/com.example.alexis.myapplication E/MYAPP: TIMEOUT
Here is the manifest declaration for permissions:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<permission android:name="com.example.alexis.myapplication.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.example.alexis.myapplication.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
And receiver:
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<!-- Receives the actual messages. -->
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<!-- Receives the registration id. -->
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.example.alexis.myapplication" />
</intent-filter>
</receiver>
Any help would be highly appreciated.
Note: I am using genymotion emulator with 2.3.7, I don't have a hardware device to test.
Used a hardware device and everything worked so it was emulator's fault.
I saw many other questions on here saying if an app is force stopped it won't receive notifications.
However, I AM NOT force stopping this app. I am just hitting the back button. I have also tried just hitting the home button. In both cases no alerts.
However, if the app is running in the foreground the PushReceived event fires and the AData.Message shows the correct text. So, it would appear that remote notifications are being sent to the device, it's just that the app is never woken up to process them.
The app is written in Delphi XE8 and I have tested this on KitKat and JellyBean, both with the same results.
I suspect the problem is in the Android Manifest file. A copy of which is below. Beyond this I am not sure where to go. As I understand it when a push is received it is supposed to run a small bit of code in the Firemonkey framework that displays the push message without starting the full app.
I am using the app described in this tutorial to try to figure out why it is not working in my live app. This used to work as I expected it to in XE7.
http://docwiki.embarcadero.com/RADStudio/XE8/en/Mobile_Tutorial:_Using_Remote_Notifications_%28iOS_and_Android%29
I am using the Engagement Tab on the Kinvey dashboard to send the test pushes, so I assume the server side is correct. And as I said they are working with the app in the foreground.
Gary
<?xml version="1.0" encoding="utf-8"?>
<!-- BEGIN_INCLUDE(manifest) -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.gwsystemsdns.net.pushtest"
android:versionCode="1"
android:versionName="1.0.0"
android:installLocation="preferExternal">
<!-- This is the platform API where NativeActivity was introduced. -->
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="11" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<permission android:name="net.gwsystemsdns.net.pushtest.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="net.gwsystemsdns.net.pushtest.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-feature android:glEsVersion="0x00020000" android:required="True"/>
<application android:persistent="False"
android:restoreAnyVersion="False"
android:label="PushTest"
android:debuggable="True"
android:largeHeap="False"
android:icon="#drawable/ic_launcher"
android:theme="#style/AppTheme"
android:hardwareAccelerated="true">
<!-- Our activity is a subclass of the built-in NativeActivity framework class.
This will take care of integrating with our NDK code. -->
<activity android:name="com.embarcadero.firemonkey.FMXNativeActivity"
android:label="PushTest"
android:configChanges="orientation|keyboard|keyboardHidden"
android:launchMode="singleTask">
<!-- Tell NativeActivity the name of our .so -->
<meta-data android:name="android.app.lib_name"
android:value="PushTest" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="com.embarcadero.firemonkey.notifications.FMXNotificationAlarm" />
<receiver android:exported="true" android:name="com.embarcadero.gcm.notifications.GCMNotification" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="net.gwsystemsdns.net.pushtest" />
</intent-filter>
</receiver>
</application>
</manifest>
<!-- END_INCLUDE(manifest) -->
My Push Received event demonstrating the reception of foreground pushes.
procedure TfrmMain.PushEvents1PushReceived(Sender: TObject; const AData: TPushData);
begin
Memo1.Lines.Add('Push Received');
Memo1.Lines.Add('Push = ' + AData.Message);
end;
I found the problem. This line was missing from the XE8 manifest template file:
<%activity%>
<service android:name="com.embarcadero.gcm.notifications.GCMIntentService" />
<%receivers%>
</application>
It goes into the AndroidManifest.template.xml file like this (immediately following the <%receivers%> tag:
<%activity%>
<service android:name="com.embarcadero.gcm.notifications.GCMIntentService" />
<%receivers%>
<receiver android:name="com.embarcadero.firemonkey.notifications.FMXNotificationAlarm" />
</application>
As per Embarcadero's docwiki.
I'm running an sample application on AIR using EasyPush extension from milkman games, and using urban airship as 3rd party server.
In IOS everything works fine, but in Android I'm not receiving the push notification. I can register the token, it appears on project menu in my urban airship account, but when i send a test message, i'm not receiving it on device.
I've checked many times my android manifest xml, but everything seems to be ok.
<manifestAdditions><![CDATA[
<manifest android:installLocation="auto">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.GET_TASKS"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<permission android:name="air.com.cafundo.testpush.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="air.com.cafundo.testpush.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-sdk android:minSdkVersion="8"/>
<uses-feature android:required="true" android:name="android.hardware.touchscreen.multitouch"/>
<application>
<activity android:name="air.com.cafundo.testpush.PushPreferencesActivity" />
<activity android:name="air.com.cafundo.testpush.LocationActivity" />
<receiver android:name="com.urbanairship.CoreReceiver" />
<receiver android:name="com.urbanairship.push.GCMPushReceiver" android:exported="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.cafundo.testpush" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REPLACED" />
<data android:scheme="package"/>
</intent-filter>
</receiver>
<service android:name="com.urbanairship.push.PushService" android:label="Push Notification Service"/>
<service android:name="com.urbanairship.analytics.EventService" android:label="Event Service"/>
<provider android:name="com.urbanairship.UrbanAirshipProvider"
android:authorities="air.com.cafundo.testpush.urbanairship.provider"
android:exported="false"
android:multiprocess="true" />
<receiver android:name="air.com.cafundo.testpush.IntentReceiver" />
<receiver android:name="com.milkmangames.extensions.android.push.MmgPushReceiver" />
</application>
</manifest>
]]></manifestAdditions>
Hope somebody can help me.
Thanks.
I'm not sure if you're still having this issue, but I made the mistake of creating a Key for Android applications when I should've been creating a Key for server applications within the Google developers console.
As soon as I used the generated server API key within UrbanAirship's "Configure Notification Services / Google Cloud Messaging (GCM)" section I started to receive the push messages.
Hope that helps.
I have push enabled for my application and my manifest is as seen below:
Package Name:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.norton.mobile"
android:versionCode="1"
android:versionName="1.0" >
My receiver is as below:
<receiver
android:name="com.pravaa.mobile.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<!-- Receives the actual messages. -->
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.stanley.mobile" />
</intent-filter>
</receiver>
With the above configuration i am able to receive notifcation succesfully on any device with OS > 4.1, but not on devices with OS < 4.1. On modifying the receiver category configuration to **<category android:name="com.norton.mobile" />** i was able to sucessfully receive notifications even on devices with OS < 4.1. I do understand that the docs say "A receiver for com.google.android.c2dm.intent.RECEIVE, with the category set as applicationPackage." But how does it work for devices with OS > 4.1 although the category does not match the applicationPackage.
Does someone know the reasoning behind this? Thanks in advance.
Maybe you wrote a wrong category name, and it worked cause a category name is not required above OS 4.1.
"
Notice that android:name in the category tag must be replaced by your application's package name (and the category tag is not required for applications targeted to minSdkVersion 16 and higher).
http://developer.android.com/google/gcm/helper.html#android-app
"
Confirm your configuration with
<!-- GCM PERMISSIONS START -->
<permission
android:name="com.norton.mobile.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.norton.mobile.permission.MAPS_RECEIVE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<permission
android:name="com.norton.mobile.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.norton.mobile.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!-- GCM PERMISSIONS END -->
<!-- GCM RECEIVER And SERVICE START -->
<receiver
android:name="com.google.android.gcm.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" />
<action android:name="com.google.android.c2dm.intent.GCM_RECEIVED_ACTION" />
<category android:name="com.norton.mobile" />
</intent-filter>
</receiver>
<service
android:name="com.norton.mobile.GCMIntentService"
android:enabled="true" />
<!-- GCM RECEIVER And SERVICE END -->
Hey everyone I have been toying around with a native extension lately for Android and I need to add Google Cloud Messaging. I was able to get the Google Cloud Messaging app to work on its own. But now that I have integrated it into a native extension for Flash I have found an issue I can't resolve.
08-21 17:58:01.661: W/ActivityManager(180): Unable to start service Intent { act=com.google.android.c2dm.intent.REGISTRATION cat=[air.GCMAppTest.debug] flg=0x10 cmp=air.GCMAppTest.debug/com.xxxxxxxxx.extensions.GCM.GCMIntentService (has extras) }: not found
This error comes up when the GCM Broadcast Receiver receives the
08-21 17:58:01.661: V/GCMBroadcastReceiver(7604): GCM IntentService class: com.gamecloudstudios.popsportsandroidane.extensions.GCM.GCMIntentService
The error is caused by the Flash Package Context being the default package.
When I need the default package to be the package containing the GCMIntentService.
Has anyone been able to get the GCMIntentService to run in an Android Flash Native Extension? or any AndroidIntentService for that matter.
You need to make sure you add the Intent Service to the manifest additions of your AIR application descriptor, not the Android manifest of your native code library. For example, the following code is what we use in our example application of our GCM native extension available here if you're interested.
There are a few things to note in there, especially the "air." prefix on some of the android names. But as long as you have all these additions, the actual implementation of the Android code should be fairly similar to the Google examples.
<android>
<manifestAdditions><![CDATA[
<manifest android:installLocation="auto">
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="8"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!-- Only this application can receive the messages and registration result -->
<permission android:name="air.com.distriqt.test.debug.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="air.com.distriqt.test.debug.permission.C2D_MESSAGE" />
<application>
<receiver android:enabled="true" android:exported="true" android:name="com.distriqt.extension.pushnotifications.PushNotificationsBroadcastReceiver" 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="air.com.distriqt.test.debug" />
</intent-filter>
</receiver>
<service android:enabled="true" android:exported="true" android:name="com.distriqt.extension.pushnotifications.gcm.GCMIntentService" />
</application>
</manifest>
]]></manifestAdditions>
</android>