I'm implementing GCM, wich teorically haves a reasonable requirement, android 2.3: https://developers.google.com/cloud-messaging/android/client
The problem is that it is working in my Android 5.1 devices and Android 4.4 devices, but it does not work in my Android 4.1 devices, LG and HUAWEI....
I can see this error in the logcat: GooglePlayServices not available due to error 2
In the previous link i can see this:
If you want to support pre-4.4 KitKat devices, add the following
action to the intent filter declaration for the receiver:
So i added it, this is what i added in the manifest:
<uses-permission android:name="android.permission.GET_ACCOUNTS" /> <!-- GCM requires a Google account. -->
<uses-permission android:name="android.permission.WAKE_LOCK" /> <!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <!-- This app has permission to register and receive data message. -->
<!-- Creates a custom permission so only this app can receive its messages. NOTE: APP_PACKAGE.permission.C2D_MESSAGE -->
<permission android:name="com.myapp.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.myapp.permission.C2D_MESSAGE" />
<!-- BroadcastReceiver that will receive intents from GCM services and handle them to the custom IntentService. -->
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
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.myapp" />
</intent-filter>
</receiver>
<service
android:name="com.myapp.util.notifications.GCMListenerService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<service
android:name="com.myapp.util.notifications.CustomInstanceIDListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID"/>
</intent-filter>
</service>
<service
android:name="com.myapp.util.notifications.RegistrationIntentService"
android:exported="false">
</service>
It is very frustrating since both devices are Android 4.1, munch higher than Android 2.3.
Also before this, with my old implementation of GCM (before google play services origins, when GCM was a .jar file called gcm.jar) works 100% fine on these 4.1 devices.
In the device 4.1 you are testing ,firstly you have to update your google play services of device..after that check your logs and show logs so that i can help you?
Related
I'm trying to enable notifications on my android app (built in react-native) using this package
Here is a part of my MANIFEST.XML file :
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="{package_name}"
android:versionCode="1"
android:versionName="1.0.0"
android:minSdkVersion="21"
android:targetSdkVersion="23">
<permission
android:name="com.xxx.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.xxx.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="com.google.android.c2dm.permission.SEND" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.GET_TASKS" />
...
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.xxx" />
</intent-filter>
</receiver>
<service android:name="com.oney.gcm.GcmRegistrationService"/>
<service android:name="com.oney.gcm.BackgroundService"></service>
<service
android:name="com.oney.gcm.RNGcmListenerService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<receiver
android:exported="false"
android:name="com.oney.gcm.GcmBroadcastReceiver">
<intent-filter>
<action android:name="com.oney.gcm.GCMReceiveNotification" />
</intent-filter>
</receiver>
<receiver android:name="io.neson.react.notification.NotificationEventReceiver" />
<receiver android:name="io.neson.react.notification.NotificationPublisher" />
<receiver android:name="io.neson.react.notification.SystemBootEventReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
</intent-filter>
</receiver>
Unfortunately, I have this in my logs when I install my app :
W/PackageManager( 873): Not granting permission com.google.android.c2dm.permission.SEND to package (protectionLevel=18 flags=0x8be46)
Any thoughts on the issue ?
Thanks.
There is a C2DM setup issue at your project level.Either go through official doc or follow this tutorial step by step.
Step to be made while changing your Manifest.xml
Permission to receive C2DM messages
Access to the internet
Restrict access to your C2DM messages so no other app can see them
Declare a Receiver, that we’ll create later, that will let us receive the C2DM events
Make sure that the minSdkVersion is set so that only 2.2 and higher can access your app
I think because you are using deprecated api
Important: C2DM was officially deprecated on June 26, 2012, and will
be shut down completely as of October 20, 2015. Existing C2DM
developers are encouraged to migrate to Google Cloud Messaging (GCM).
See the C2DM-to-GCM Migration document for more information.
Developers must use GCM for new development.
https://developers.google.com/android/c2dm/?csw=1#manifest
I did as the example
Hello World Android app
in my manifest
<?xml version="1.0"?>
<!-- Google Analytics required permissions -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- Optional permission for reliable local dispatching on non-Google Play devices -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat"
android:name=".MyApp">
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version"/>
<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>
<!-- Enable background dispatching to improve delivery on non-Google Play devices -->
<receiver
android:name="com.google.android.gms.analytics.AnalyticsReceiver"
android:enabled="true">
<intent-filter>
<action android:name="com.google.android.gms.analytics.ANALYTICS_DISPATCH"/>
</intent-filter>
</receiver>
<service
android:name="com.google.android.gms.analytics.AnalyticsService"
android:enabled="true"
android:exported="false"/>
<!-- Enable Google Play Store Campaign reports -->
<receiver
android:name="com.google.android.gms.analytics.CampaignTrackingReceiver"
android:exported="true"
android:enabled="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER"/>
</intent-filter>
</receiver>
<service
android:name="com.google.android.gms.analytics.CampaignTrackingService"
android:enabled="true"/>
</application>
and I have the MyApp as normal but every time I run the app these messages appear and I cant see and thing in analytics/web/
07-22 17:19:47.506 20695-20695/? W/GAv4﹕ AnalyticsReceiver is not registered or is disabled. Register the receiver for reliable dispatching on non-Google Play devices. See [google link] for instructions.
07-22 17:19:47.546 20695-20695/? W/GAv4﹕ CampaignTrackingReceiver is not registered, not exported or is disabled. Installation campaign tracking is not possible. See [google link] for instructions.
07-22 17:19:47.546 20695-20722/? W/GAv4﹕ AnalyticsService not registered in the app manifest. Hits might not be delivered reliably. See [google link] for instructions.
FIXED
I dont know what happened I just took a rest and all things were fine
I am developing an AIR application and I implemented push notifications for Android using GCM. The service works perfectly on all devices except those having Android 5.0 or 5.1 OS. The application simply doesn't receive a registration id from GCM.
Neither PERMISSION_GIVEN_WITH_TOKEN_EVENT nor PERMISSION_REFUSED_EVENT are never raised. I am not getting any response from GCM.
Did anybody have this problem? Could you please help me?
I am using Air Native Extension for Push Notifications from Freshplanet github.com/freshplanet/ANE-Push-Notification
So this is my code:
PushNotification.getInstance().registerForPushNotification(GOOGLE_PROJECT_ID); PushNotification.getInstance().addEventListener(PushNotificationEvent.PERMISSION_REFUSED_EVENT, onPushNotificationTokenFailed);
function onPushNotificationToken(event:PushNotificationEvent):void {
trace("My push token is: " + event.token);
}
function onPushNotificationTokenFailed(event:PushNotificationEvent):void
{
trace(event.errorCode);
trace(event.errorMessage);
trace();
}
And my manifest file (partial):
<permission android:name="MY_APP_ID.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="MY_APP_ID.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<application>
<activity android:name="com.freshplanet.nativeExtensions.NotificationActivity" android:theme="#android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
<receiver android:name="com.freshplanet.nativeExtensions.C2DMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="MY_APP_ID" />
</intent-filter>
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="MY_APP_ID" />
</intent-filter>
</receiver>
<service android:name="com.freshplanet.nativeExtensions.LocalNotificationService"/>
<receiver android:name="com.freshplanet.nativeExtensions.LocalBroadcastReceiver" android:process=":remote">
</receiver>
Thanks in advance!
I encountered a strange problem - I am using GCM with my application for a month but now its has stopped working on my nexus 4 (running Lollipop 5.0.1, stock Android).Everytime I try to get a registration id from Google server it returns me Error :PHONE_REGISTRATION_ERROR .I know this error is for devices that runs android version 2.2 and below as they do not support GCM but why is it happening for my device although it was working few days back.
<permission
android:name="diver.volo.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="diver.volo.permission.C2D_MESSAGE" />
<receiver
android:name="diver.volo.components.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="diver.volo" />
</intent-filter>
</receiver>
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 -->