How configure GCM for an Android Device Policy Controller (DPC) - android

I want to use the demo application TestDPC released by Google to create a Work Profile with my own device policy controller so I added some code to this app in order to connect to GCM service to receive cloud messages to start some actions on my device.
To connect to GCM I used some example code that I tested separately and it works, the only thing I added is a boot listener (ReceiverStarter) in order to activate GCM listener everytime the user reboot his device.
The strange thing is that when I install my app on device (Samsung Note 4 with Android 5.1.1 API 22) without create a managed profile the GCM client works properly.
If with the app early installed I create a work profile and the app itslef take control over the new profile the same code for GCM doesn't work anymore.
I can see (using notifications) that in this case my dpc app can register to GCM and fetch GCM ID and I can read it in my console but the listener (MyGcmListenerService) doesn't receive any cloud messages as if the listener is not up and running, I cannot see any errors and/or logs in my console.
Maybe I need some more permissions?
Here my manifest
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-permission android:name="android.permission.PACKAGE_USAGE_STATS" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.xxx.emmagent.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.xxx.emmagent.permission.C2D_MESSAGE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:theme="#style/AppTheme"
android:label="#string/app_name">
<activity
android:name=".LaunchActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name=".gcm.MainActivity"
android:label="#string/app_name"
android:theme="#style/SetupTheme"/>
<activity
android:name=".PolicyManagementActivity"
android:label="#string/app_name"
android:windowSoftInputMode="adjustPan"/>
<activity
android:name=".AddAccountActivity"
android:label="#string/app_name"
android:theme="#style/SetupTheme"/>
<activity
android:name=".EnableProfileActivity"
android:label="#string/app_name"
android:theme="#style/SetupTheme"/>
<activity
android:name=".EnableDeviceOwnerActivity"
android:label="#string/app_name"
android:theme="#style/SetupTheme"/>
<activity
android:name=".cosu.EnableCosuActivity"
android:label="#string/app_name"
android:theme="#style/SetupTheme"/>
<activity
android:name=".syncauth.SetupSyncAuthManagement"
android:label="#string/app_name"
android:theme="#style/SetupTheme"/>
<activity
android:name=".syncauth.FinishSyncAuthDeviceOwnerActivity"
android:label="#string/app_name"
android:theme="#style/SetupTheme"/>
<activity
android:name=".syncauth.FinishSyncAuthProfileOwnerActivity"
android:label="#string/app_name"
android:theme="#style/SetupTheme"/>
<activity
android:name=".policy.locktask.KioskModeActivity"
android:label="#string/kiosk_mode"
android:launchMode="singleInstance"
android:lockTaskMode="if_whitelisted"
android:enabled="false">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<receiver
android:name=".DeviceAdminReceiver"
android:description="#string/app_name"
android:label="#string/app_name"
android:permission="android.permission.BIND_DEVICE_ADMIN">
<meta-data
android:name="android.app.device_admin"
android:resource="#xml/device_admin_receiver"/>
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED"/>
<action android:name="android.app.action.PROFILE_PROVISIONING_COMPLETE"/>
</intent-filter>
</receiver>
<provider
android:authorities="com.xxx.emmagent.fileprovider"
android:name="android.support.v4.content.FileProvider"
android:grantUriPermissions="true"
android:exported="false">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/filepaths" />
</provider>
<!-- GCM messagging -->
<!-- [START gcm_receiver] -->
<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.emmagent" />
</intent-filter>
</receiver>
<!-- [END gcm_receiver] -->
<!-- [START gcm_listener] -->
<service
android:name=".gcm.MyGcmListenerService"
android:exported="true" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<!-- [END gcm_listener] -->
<!-- [START instanceId_listener] -->
<service
android:name=".gcm.MyInstanceIDListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID"/>
</intent-filter>
</service>
<!-- [END instanceId_listener] -->
<service
android:name=".gcm.RegistrationIntentService"
android:exported="false">
</service>
<receiver android:name=".gcm.ReceiverStarter" android:enabled="true" android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
</application>
I don't think it depends by code, as I said the same app and the same code without a work profile works well.
Any ideas?
Thanks in advance
EDIT: here the same problem

according my knowledge the OS avoid triggering any managed profile intents from the personal profile as well (unless grant privileges). So although the request is reserved to the device from GCM, the device is unable to trigger your app's activities when the app is in the managed profile.
What you have to do is keep a separate unit in the personal profile which handles receiving GCM operations. You can grant privileges to certain intents to be cross share to the managed profile. In that way you can send the trigger though an intent to the app in the managed profile with relevant information to the operation.
Let me know if it is not clear.
Please go through this link (Ensuring Compatibility with Managed Profiles) to understand enabling cross profile intents.

Related

Google Analytics not communicating to server - AnalyticsReceiver is not registered or is disabled - error

I have setup react native firebase on my android react-native app to track app hits on analytics. But the hits are not reaching from android emulator. So, I checked the log with adb logcat and found out the below warnings and suspect that this might be causing the issue.
AnalyticsReceiver is not registered or is disabled. Register the receiver for reliable dispatching on non-Google Play devices. See link for instructions.
CampaignTrackingReceiver is not registered, not exported or is disabled. Installation campaign tracking is not possible. See link for instructions.
AnalyticsService not registered in the app manifest. Hits might not be delivered reliably. See link for instructions.
I followed this post and did some changes to the manifest file.
Modified AndroidManifest.xml file:
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.truuue.truuuerental">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:name=".MainApplication"
android:label="#string/app_name"
android:icon="#mipmap/ic_launcher"
android:allowBackup="false"
android:theme="#style/AppTheme">
<meta-data android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id"/>
<activity android:name="com.facebook.FacebookActivity"
android:configChanges=
"keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="#string/app_name" />
<activity
android:name="com.facebook.CustomTabActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="#string/fb_login_protocol_scheme" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.DOWNLOAD_COMPLETE"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="truuuetenant" android:host="*" />
</intent-filter>
</activity>
<receiver android:name="com.appsflyer.SingleInstallBroadcastReceiver" android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
<!-- Optionally, register AnalyticsReceiver and AnalyticsService to support background dispatching 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"/>
<!-- Optionally, register CampaignTrackingReceiver and CampaignTrackingService to enable
installation campaign reporting -->
<receiver android:name="com.google.android.gms.analytics.CampaignTrackingReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
<service android:name="com.google.android.gms.analytics.CampaignTrackingService" />
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
<!-- You will only need to add this meta-data tag, but make sure it's a child of application -->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyB3stzerjTZEubg4WqkF1mJeqAB7TcnXj0"/>
<uses-library
android:name="org.apache.http.legacy"
android:required="false" />
</application>
</manifest>
But still the error is appearing. Any idea on how to solve this issue?
According to the mail that I recently received from Google Analytics team,
What does “stopped processing” mean?
New data you send to the Google Analytics properties listed above will
not be serviced and will therefore, not appear on your reports. This
will appear as though you are no longer sending app data to Google
Analytics.
What will happen to my Google Analytics properties listed above?
Reporting access through our UI and API access will remain available for these properties’ historical data until January 31,
2020.
After our service is fully turned down in February 2020, these legacy properties will no longer be accessible via our Google
Analytics UI or API, and the associated data will be deleted from
Google Analytics servers. In advance of this turndown, we recommend
that you retrieve this historical data through report exports.
NOTE: Bottomline, it is advised to follow and use the Firebase Analytics for reports.

Unable to receive PushIO notifications

I made an android app according to this guide: http://docs.oracle.com/cloud/latest/marketingcs_gs/OMCFA/android/step-by-step/
I have used standard xml configuration. I am able to register my device into the PushIO and this is my log:
D/pushio﹕ Google Play Services found, using GCM for notification service.
D/pushio﹕ mRegisteringNotificationPreferences: null,mScheduledNotificationPreferences: null
D/pushio﹕ Get All PushIO Preferences
D/pushio﹕ mPushIOPersistenceManagerMap: 0
D/pushio﹕ Scheduling a new registration in 15 seconds
I/Broadcast registered﹕ true
D/Activity﹕ #1 setTransGradationModeColor false
D/OpenGLRenderer﹕ Enabling debug mode 0
D/pushio﹕ Starting registration...
D/pushio﹕ Register - Request String: dt=xxx
D/pushio﹕ Registration with push.io servers successful!
The problem is, I never receive any notification.
On top of that, the PushIO manager from which I am pushing doesn't show any number of 'Sent' notifications, though it shows on top of the image, that it was sent. See picture (might be just a bug in the UI, not sure):
My Manifest.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.example.otoincreasedk.increasepushio">
<uses-permission android:name="com.example.otoincreasedk.increasepushio.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET"/>
<permission android:name="com.example.otoincreasedk.increasepushio.permission.PUSHIO_MESSAGE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.example.otoincreasedk.increasepushio.permission.PUSHIO_MESSAGE"/>
<permission android:name="com.example.otoincreasedk.increasepushio.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme"
tools:node="replace">
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<receiver android:name="com.pushio.manager.PushIOBroadcastReceiver"
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.otoincreasedk.increasepushio" />
</intent-filter>
</receiver>
<activity android:name="com.pushio.manager.PushIOActivityLauncher" android:exported="true" />
<service android:name="com.pushio.manager.PushIOGCMIntentService" />
<service android:name="com.pushio.manager.PushIOEngagementService" />
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!--
<receiver
android:name="com.example.otoincreasedk.increasepushio.NotificationBroadcastReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.example.otoincreasedk.increasepushio.PUSHIOPUSH"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
-->
</application>
</manifest>
My MainActivity's onCreate method:
// Instantiate the Push IO Manager:
PushIOManager pushIOManager = PushIOManager.getInstance(this);
// Ensure that any registration changes with Google get reflected with Push IO.
// Also registers for Broadcast Push Notifications (All Users).
pushIOManager.ensureRegistration();

Google Analytics V4 Not showing data

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

google cloud messaging not working in android 4.4

I have an andorid application that uses GCM (not the new google cloud messaging API)
the notification is working without any problems in all android vesion except 4.4 (nexus 5)
<receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND">
<!-- Receive the actual message -->
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
<category android:name="com.PushNotifications"/>
</intent-filter>
<!-- Receive the registration id -->
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION"/>
<category android:name="com.PushNotifications"/>
</intent-filter>
</receiver>
in android 4.4. GCMBroadcastReciver is not receiving the com.google.android.c2dm.intent.RECEIVE intent, only the com.google.android.c2dm.intent.REGISTRATION
I know that the old GCM is deprecated but I don't want use yet the Google Play Services and the new API, instead I want to understand why it's not working in 4.4
Thanks
full Android Manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.PushNotifications" android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="19"/>
<supports-screens android:smallScreens="false" android:normalScreens="true" android:largeScreens="false"/>
<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"/>
<!-- Push permissions -->
<permission android:name="com.PushNotifications.permission.C2D_MESSAGE" android:protectionLevel="signature"/>
<uses-permission android:name="com.PushNotifications.permission.C2D_MESSAGE"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.USE_CREDENTIALS"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application android:label="#string/app_name" android:debuggable="true" android:icon="#drawable/icon">
<activity android:name=".PushNotifications" android:label="#string/app_name" android:configChanges="orientation|keyboardHidden|screenSize" android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="com.PushNotifications.PushNotifications.NOTIFICATION"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<!-- Preference Activity -->
<activity android:name="com.sample.common.WLPreferences" android:label="Sample"></activity>
<!-- Push service -->
<!-- In order to use the c2dm library, an application must declare a class with the name C2DMReceiver, in its own package, extending com.google.android.c2dm.C2DMBaseReceiver
It must also include this section in the manifest, replacing "com.google.android.apps.chrometophone" with its package name. -->
<service android:name=".GCMIntentService"/>
<service android:name=".ForegroundService"/>
<!-- Only google service can send data messages for the app. If permission is not set - any other app can generate it -->
<receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND">
<!-- Receive the actual message -->
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
<category android:name="com.PushNotifications"/>
</intent-filter>
<!-- Receive the registration id -->
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION"/>
<category android:name="com.PushNotifications"/>
</intent-filter>
</receiver>
</application>

Specific device not receiving Google Cloud Messaging notifications

I have an application where I'm implementing Google Cloud Messaging notifications, but in a specific device the messages don't arrive. This device has the minimum requirements to use GCM (Android version 2.2, Play Store installed and an Google Account logged). In the log I see that the device is receiving the registration id and sending to the back-office where I have a list of devices registered.
My question is: Do I need to make extra configurations to make the device receive these notifications?
Here is the manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="br.com.testegcm"
android:versionCode="1"
android:versionName="1" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="18" />
<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.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" />
<application
android:name="TesteGCM"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<receiver
android:name="br.com.testegcm.GcmBroadcastReceiver"
android:exported="true"
android:enabled="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="br.com.testegcm" />
</intent-filter>
</receiver>
<service android:name="br.com.testegcm.GcmIntentService" />
<activity
android:name="br.com.testegcm.Home"
android:screenOrientation="portrait"
android:label="#string/app_name"
android:theme="#style/notitle" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Change this :
<permission android:name="com.example.gcm.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.gcm.permission.C2D_MESSAGE" />
to :
<permission android:name="br.com.testegcm.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="br.com.testegcm.permission.C2D_MESSAGE" />
Add the same issue and i eventually i realized that i need to change in the manifest, the broadcast receiver package name from com.example.gcm to my package name :
<!-- Push notifcations-->
<receiver
android:name=".BroadcastRecivers.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
<category android:name="com.example.gcm"/>
</intent-filter>
</receiver>
To
<!-- Push notifcations-->
<receiver
android:name=".BroadcastRecivers.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
<category android:name="MY PACKAGE NAME"/>
</intent-filter>
</receiver>
No apart from Android version 2.2, Play Store app installed and an Google Account logged in no other configuration is needed, Now there are only two cases left
1) Either there is some ambiguity in your code.
2) or may be it is a device specific issue.
I had the very same problem.My code would work on nexus4(Kitkat) but would fail to get me a notification from the appln server(via gcm server).For versions less that 4.0.4 you should make sure that you have your google account setup on your device for gcm to work. I had google account on my phone but the mistake I made was that my Account and Sync settings in my galaxy ace was 'Off'.When I turned it ON and ran my code, i received the notification.
Please check the following solution. if still didn't work, let me know.
Add RECEIVE and REGISTRATION Intent in two different intent filters
<receiver
android:name=“<.GCM BroadcastReceiver Name>“ // Name of your BroadcastReceiver, define in code.
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=“<Package Name>" />
</intent-filter>
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name=“<Package Name>" />
</intent-filter>
</receiver>
<service android:name=“<.GCM IntentService Name>" /> // Name of your IntentService, define in code.
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
Add RECEIVE and REGISTRATION Intent in two different intent filters as shown as above otherwise it won’t work for some devices(Ex. HTC).

Categories

Resources