IntentReceiver not called with Android Versions < 4.1 - android

I am using Android Studio. I implemented an push service in my app. It is working with all kind of devices with newer Android versions, however it won't work with an Galaxy S2 Mini with Android 2.3.6.
The device receives pushs from other apps with Urban Airship libraries.
Relevant parts of the Manifest:
<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.my_app.app.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.my_app.app.permission.C2D_MESSAGE" />
<receiver
android:name=".IntentReceiver"
android:permission="com.google.android.c2dm.permission.SEND"
>
<intent-filter
android:priority="100">
<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.C2D_MESSAGE" />
<category android:name="com.my_app.app" />
</intent-filter>
</receiver>
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<service android:name=".GCMIntentService"
android:enabled="true"/>
IntentReceiver.java:
import android.support.v4.content.WakefulBroadcastReceiver;
public class IntentReceiver extends WakefulBroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
//doing some stuff & starting my service here,
//never gets called with said device
}
}
The device gets registered with push. I have to call it twice before the id is returned, but the right Id is saved in my backend (I send the push manually anyways, so that shouldn't be the issue). I also register a second receiver from code when the app is in foreground, but none of them gets called.
If I add <uses-permission android:name="android.permission.C2D_MESSAGE" /> in my Manifest, I receive an com.google.android.c2dm.intent.REGISTRATION action when I send a push.
I had the same issue with an Galaxy Tab. Before updating it received a "com.google.android.c2dm.intent.REGISTRATION" with every push (with intent.getStringExtra("unregistered") set). So instead of getting RECEIVE it just was unregistered, just like the Galaxy Mini. I then updated it to 4.2.2. It now gets a RECEIVE every push like it should.
I rarely read about this very problem (not receiving pushs with < 4.1). But I didn't find a solution.
I wonder if anyone experienced something similar and found a solution or if somebody sees a problem with my manifest.

So, apparently not all package names in the manifest are replaced by build.gradle. In my case (with Android Studio 0.8) it was the custom permission that was wrong. I am using flavours, I guess I should have mentioned that. The package name in the custom permission has to be the package name including flavour, like this:
<permission
android:name="com.my_app.app.myflavour.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.my_app.app.myflavour.permission.C2D_MESSAGE" />

Related

Push notifications behaviour while app running in background (Parse/Unity/Android)

I've been trying Parse's integration tutorials and examples, and I can't figure out how to make the push notifications show in tray when the app is running in background.
Notifications do appear when the app is closed, though!
Also, when in foreground, push notification events do trigger correctly.
Summing up, push notifications work perfectly except when running in background.
The notification shows in the log like this:
07-02 04:43:06.979: I/GCM(22111): GCM message com.parse.parseunitypushsample 0:1435804985959681%368c544ef9fd7ecd
07-02 04:43:07.033: W/GCM-DMM(22111): broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE pkg=com.parse.parseunitypushsample (has extras) }
07-02 04:43:07.041: I/ParsePushService(16145): Push notification received. Payload: {"alert":"A test push from Parse!","push_hash":"2bf06f5e2a92eab2fcb855fc1117fa33"}
07-02 04:43:07.041: I/ParsePushService(16145): Push notification is handled while the app is foregrounded.
Notice it says "foregrounded", even when some other app is in foreground. This bothers me a bit, as if Parse decided not to show the notification because it concludes that it's on foreground. Just my guess.
I'm using:
Unity 5.1.1f1 (free)
Android 5.1.1
Parse and tutorial project provided here: https://parse.com/apps/quickstart#parse_push/unity/android/new (with only modifications needed to make it run in Unity 5.x)
Provided manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.parse.parseunitypushsample" android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="10" />
<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.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:protectionLevel="signature" android:name="com.parse.parseunitypushsample.permission.C2D_MESSAGE" />
<uses-permission android:name="com.parse.parseunitypushsample.permission.C2D_MESSAGE" />
<application android:label="#string/app_name" android:icon="#drawable/app_icon">
<!-- Added "com.unity3d.player" below to avoid crash -->
<activity android:name="com.unity3d.player.UnityPlayerActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="com.parse.ParsePushBroadcastReceiver" 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.parseunitypushsample" />
</intent-filter>
</receiver>
<service android:name="com.parse.ParsePushService" />
</application>
</manifest>
I'm just building the tutorial project, but it needs Unity upgrade, and a couple small fixes to run. Otherwise, it's clean and seems to correctly receive push notifications, but not showing them while running on background.
Is that the expected behaviour, or am I doing something wrong?
Thank you :)
If you got that, then you are almost there! I think you need to add this script to one of your GameObjects:
using UnityEngine;
using System.Collections;
using Parse;
public class ParsePushRegistration : MonoBehaviour {
// Use this for initialization
void Start () {
#if UNITY_ANDROID
ParsePush.ParsePushNotificationReceived += (sender, args) => {
AndroidJavaClass parseUnityHelper = new AndroidJavaClass ("com.parse.ParseUnityHelper");
AndroidJavaClass unityPlayer = new AndroidJavaClass ("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject> ("com.unity3d.player.UnityPlayerNativeActivity");
// Call default behavior.
parseUnityHelper.CallStatic ("handleParsePushNotificationReceived", currentActivity, args.StringPayload);
};
#endif
}
}
Check and keep track of this question, it might be usefull to you:
Parse Unity Push Sample not working
Not sure if this helps, but I was able to work around this by editing the plugin source available here. To do this I simply cached the string value of the push msg in the ParsePushUnityHelper.java class and then retrieved it from Unity c# via Android CallStatic method. You can then use one of the publicly available Json modules to convert this from a json string to a dictionary. Keep in mind you'll have to recompile and link the plugin .jar to your Unity project. Good luck!

onRegistered() from GCMIntentService never called

I am trying to register my app on GCM but I don't know why my app is never registered. GCMRegistrar.register(this, SENDER_ID); is called but onRegistered() from my GCMIntentService is never called. I don't know WHY.
This is my Logcat
01-17 11:03:00.015: D/GCMRegistrar(3509): resetting backoff for com.abc.xyz.ui.activity
01-17 11:03:03.210: V/GCMRegistrar(3509): Registering app com.abc.xyz.ui.activity of senders 964256581311
01-17 11:03:06.070: V/GCMBroadcastReceiver(3509): onReceive: com.google.android.c2dm.intent.REGISTRATION
01-17 11:03:06.070: V/GCMBroadcastReceiver(3509): GCM IntentService class: com.abc.xyz.ui.activity.GCMIntentService
01-17 11:03:06.070: V/GCMBaseIntentService(3509): Acquiring wakelock
and this is my complete manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.abc.xyz.ui.activity"
android:versionCode="1"
android:versionName="1.5.6" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-sdk
android:minSdkVersion="11" android:targetSdkVersion="16"/>
<uses-feature
android:name="android.hardware.usb.host"/>
<!-- This app has permission to register and receive data message. -->
<uses-permission
android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission
android:name="android.permission.INTERNET" />
<uses-permission
android:name="android.permission.READ_PHONE_STATE" />
<uses-permission
android:name="android.permission.GET_TASKS" />
<uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission
android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission
android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission
android:name="android.permission.CALL_PHONE" />
<uses-permission
android:name="android.permission.BLUETOOTH" />
<!-- GCM requires a Google account. -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!--
Creates a custom permission so only this app can receive its messages.
NOTE: the permission *must* be called PACKAGE.permission.C2D_MESSAGE,
where PACKAGE is the application's package name.
-->
<uses-permission
android:name="com.abc.xyz.ui.activity.permission.C2D_MESSAGE" />
<permission
android:name="com.abc.xyz.ui.activity.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.Holo.Light"
android:name="com.abc.xyz.MyApplication"
android:allowBackup="false">
<activity
android:name=".StartupActivity"
android:noHistory="true"
android:label="#string/title_startup_screen"
android:configChanges="orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".LoginActivity"
android:windowSoftInputMode="stateAlwaysVisible|adjustResize"
android:label="#string/title_login_screen"
android:configChanges="orientation">
</activity>
//my other activity defination
<!--
BroadcastReceiver that will receive intents from GCM
services and handle them to the custom IntentService.
The com.google.android.c2dm.permission.SEND permission is necessary
so only GCM services can send data messages for the app.
-->
<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
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.abc.xyz.ui.activity" />
</intent-filter>
</receiver>
<!--
Application-specific subclass of GCMBaseIntentService that will
handle received messages.
By default, it must be named .GCMIntentService, unless the
application uses a custom BroadcastReceiver that redefines its name.
-->
<service android:name="com.abc.xyz.ui.activity.GCMIntentService" />
</application>
</manifest>
I don't know what is wrong and why onRegistered() is never called. Any help will be appreciated.
I figured out in another post what is the problem. My GCMIntentService Class was defined in my manifest as
<service android:name="MY_PACKAGE.gcm.GCMIntentService" />
because I didn't want to put this class at the root package, instead I put at MY_PACKAGE.gcm". This seems to cause a problem and as the documentation says,
Add the following intent service
<service android:name=".GCMIntentService" />
So when I moved to the root package it worked! There is another way to put the GCMIntentServiceSubclass wherever you want and name it differently. You should subclass GCMBroadcastReceiver and do the changes in manifest and in the subclass as shown in this other post.
I answer because pasting code is barely readable in comments:
I am missing some logs from your logcat that suggest your service is even called. I have this in my Logcat when registering:
GCMBroadcastReceiver V onReceive: com.google.android.c2dm.intent.REGISTRATION
GCMBroadcastReceiver V GCM IntentService class: com.package.android.app.GCMIntentService
GCMBaseIntentService V Acquiring wakelock
GCMBaseIntentService V Intent service name: GCMIntentService-DynamicSenderIds-1
Especially the last line is missing or you have forgotten to paste it. Could you make sure that you posted the complete LogCat? Filter for GCM to make sure you didn't missed something.
Update
As the OP mentioned in the comments, he used the service to do more. This somehow interfered with the GCM functionality and after separating this into two services it worked. Lessons learned: Don't use the GCMIntentService for anything else than GCM.

GCM Android: onRegistered() not being called

I'm having a problem with GCM on Android. It fails to execute the onRegistered() callback, or ever return a good regId, on one of my test devices (Droid2) - but it works perfectly well on another device (Galaxy Nexus).
I'm following the basic example here. The caller looks like this:
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
final String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals(""))
GCMRegistrar.register(this, Constants.SENDER_ID);
else
Log.v(TAG, "Already registered");
And my manifest has this:
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
and
<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" />
<category android:name="com.gcl.myapp" />
</intent-filter>
</receiver>
Why isn't the onRegistered() callback working? And what could be causing it to work on one device, but fail on another?? Thanks.
If it works on some devices but not others then it is to do with one of the following:
Pre Android 4.0.4 the device requires a valid google account to work.
GCM only works on devices with Play Store App and API 8 onwards.
Your manifest is badly formatted - use Lint to check!
Device/App is already registered, the Play implementation may not return again.. Try GCMRegistrar.unregister(this); first.
Hope that helps!
I had the same problem. If you are using AngularJS + IonicFramework you do not have to do this:
After you create your factory with your onDeviceReady function, creates onNotificationGCM function. Something like this:
app.factory('PushProcessingService', function () {
..
});
function onNotificationGCM(e) {
}
I was creating onNotificationGCM inside my factory. This solve my problem.

GCM with custom broadcastreceiver

I am implementing gcm notifications in my application. Because I use my code to generate lot of application with different package names I cannot use standard mypackage.GCMIntentService name. When generating applications I do changes only in Manifest and change imports of my R class. So I impelented my own BroadcastReceiver
public class GCMReceiver extends GCMBroadcastReceiver {
#Override
protected String getGCMIntentServiceClassName(Context context) {
return GCMIntentService.class.getName();
}
}
to return name of GCMIntentService regardless of package name.
Here is my manifest:
<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="org.rferl.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="org.rferl.permission.C2D_MESSAGE" />
<service
android:name="org.rferl.service.GCMIntentService"
android:enabled="true" />
<receiver
android:name="org.rferl.GCMReceiver"
android:enabled="true"
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="org.rferl" />
</intent-filter>
</receiver>
Everything works fine, I can register, unregister, receive messages. But when application is not runnig no GCMIntentService.onMessage is not called. Am I missing something in my manifest? Why system did not start service?
To change package/class name for application/GCMIntentService/GCMBroadcastReceiver for Android GCM (using Eclipse ADT)
Note: You are advised to verify that you can receive messages through GCM before making the following changes. To implement GCM in Android app using the application's default package name, see GCM: Getting Started.
Package name
To change package name of your app (e.g., new package name = com.example.newpackage),
In Package Explorer, right click the project → Android Tools → Rename Application Package.
This updates the package name automatically and conveniently.
In AndroidManifest.xml, update the package name in permission and uses-permission for C2D_MESSAGE:
<permission android:name="com.example.newpackage.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.example.newpackage.permission.C2D_MESSAGE" />
In AndroidManifest.xml, update the package name in category of the receiver:
<receiver
android:name="com.example.oldpackage.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" > <!-- Not this one!! -->
<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.newpackage" /> <!-- This one!! -->
</intent-filter>
</receiver>
Name of GCMIntentService
If your app's package name is com.example.newpackage, your GCMIntentService must be called com.example.newpackage.GCMIntentService. If not,
Create a new class that extends GCMBroadcastReceiver and override getGCMIntentServiceClassName():
public class MyBroadcastReceiver extends GCMBroadcastReceiver
{
#Override
protected String getGCMIntentServiceClassName(Context context)
{
return MyIntentService.class.getName(); // Don't hard-code like "com.example.oldpackage.MyIntentService", see http://stackoverflow.com/a/936696/1402846
}
}
this is based on Google's documentation on GCMBroadcastReceiver:
By default, the GCMBaseIntentService class belongs to the application main package and is named DEFAULT_INTENT_SERVICE_CLASS_NAME. To use a new class, the getGCMIntentServiceClassName(Context) must be overridden.
In AndroidManifest.xml, update the name of the receiver:
<receiver
android:name="com.example.oldpackage.MyBroadcastReceiver"
... >
</receiver>
In AndroidManifest.xml, update the name of the service:
<service android:name="com.example.oldpackage.MyIntentService" />
Name of GCMBroadcastReceiver
If your changed the package/class name of GCMBroadcastReceiver:
In AndroidManifest.xml, update the name of the receiver:
<receiver
android:name="com.example.oldpackage.NewBroadcastReceiver"
... >
</receiver>
Troubleshooting
Verify that in AndroidManifest.xml, the package name should appear at least 4 times:
In manifest:
<manifest ...
package="com.example.newpackage" ...
In permission:
<permission android:name="com.example.newpackage.permission.C2D_MESSAGE" android:protectionLevel="signature" />
In uses-permission:
<uses-permission android:name="com.example.newpackage.permission.C2D_MESSAGE" />
In category within intent-filter within receiver for the GCM broadcast receiver:
<category android:name="com.example.newpackage" />
If you changed your package name, uninstall the old app on your device/emulator before testing.
If you changed your package name, notice that the registration ID (that you receive in onRegistered()) has changed.
If you received your registration ID in onRegistered(), you should see something like this in LogCat (tag GCMBroadcastReceiver):
GCMBroadcastReceiver onReceive: com.google.android.c2dm.intent.REGISTRATION
GCMBroadcastReceiver GCM IntentService class: com.example.oldpackage.MyIntentService
Verify that the package/class name of the intent service is correct.
If you override getGCMIntentServiceClassName(Context) in your own GCMBroadcastReceiver, you should see something like this in LogCat (tag GCMRegistrar):
GCMRegistrar Setting the name of retry receiver class to com.example.oldpackage.MyBroadcastReceiver
Verify that the package/class name of the broadcast receiver is correct.
When your server sends a message to GCM server, check the HTTP status code and HTTP response for errors.
And if you are desperate:
Check LogCat for errors.
Try restarting your device/emulator.
Try uninstalling your app on the device/emulator.
Try restarting Eclipse.
Try clean and re-build the project.
Try updating ADT (Pull down menu → Window → Android SDK Manager → Install packages).
Try updating Eclipse (Pull down menu → Help → Check for Updates).
Try restarting your computer.
Get a good sleep, or pray.
You should put GCMIntentService class into your root application package.
Here org.rferl
<service
android:name=".GCMIntentService"
android:enabled="true" />
and receiver
<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
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.EgoSecure.ma" />
</intent-filter>
</receiver>
Because I use my code to generate lot of application with different package names I cannot use standard mypackage.GCMIntentService name.
I'm not sure whether you ask for a runtime or a build time solution. The other answers are runtime solutions so I thought I add some information on possibilites during build time.
In AndroidManifest, you can use the variable $PACKAGE_NAME (available by default) which will refer to the package name you specified in the attribute package in the manifest root element.
The value of this package attribute needs not be a hard coded string but can also be set dynamically via resource reference like so:
<manifest package="#string/app_package" ...>
...
<service
android:name="$PACKAGE_NAME.service.GCMIntentService"
android:enabled="true" />
...
</manifest>
Note .service is just a subpackage that I included to show how you specify these. Of course, this solution would work only if your applications follow general rules like putting Service classes in a .service subpackage.
Also note, that you can actually leave the root package off completely. It will be expanded by Android:
<manifest package="#string/app_package" ...>
...
<service
android:name=".service.GCMIntentService"
android:enabled="true" />
...
</manifest>
In effect, same as above.
If you are looking for a more flexible way to replace values in an AndroidManifest (or different files), you might want to have a look at the Ant Replace task (http://ant.apache.org/manual/Tasks/replace.html) or Resource Filtering (http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html) with Maven.
The gcm broadcast receiver (GCMBroadcastReceiver.class) calls intent service class (GCMIntentService.class) from application root directory. You cannot use "org.rferl.service.GCMIntentService" right now. You should override getGCMIntentServiceClassName method from GCMBroadcastReceiver, that returns name of your GCMIntentService class. How to do that, here

Problem registering for C2DM in Android

I'm trying to test the C2DM framework. I got the confirmation email a couple of days ago and then tryied to create a client that could register. For that purpose, I created a simple client following the steps described in this tutorial: http://code.google.com/intl/es-419/android/c2dm/index.html.
The Android manifest file contains among other things this code:
<permission android:name="com.bilthon.ufrj.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.bilthon.ufrj.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.INTERNET"/>
<receiver android:name=".C2DMReceiver" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.bilthon.ufrj" />
</intent-filter>
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.bilthon.ufrj" />
</intent-filter>
</receiver>
And then, the main activity launched when the program starts has the following code:
Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER");
registrationIntent.putExtra("app", PendingIntent.getBroadcast(this, 0, new Intent(), 0)); // boilerplate
registrationIntent.putExtra("sender","mytestemail#gmail.com");
Log.d("WelcomeScreen","mytestemail#gmail.com");
startService(registrationIntent);
I also registered a google account on the AVD running my client, as they said it was required. But the problem is that I cannot get the broadcast receiver to "wake up". I don't know what could be wrong. By analysing the logs, I can see that the registration intent is created and apparently used correctly, but the receiver code just never is executed, what could be wrong?
Thanks in advance
Nelson
Well.. just sorted it out, the problem was with the declaration of the receiver. The tags for the receiver should go inside the application tag, just as demonstrated here: http://developer.android.com/guide/topics/manifest/manifest-intro.html
Here's an example of a well formated Manifest for a C2DM application. Thanks to Mark Murphy for posting the link at the android-c2dm group.
And sorry for the silly mistake.
Nelson
I just got this working myself after wrestling with it for some time.
In the manifest, you have the line
<receiver android:name=".C2DMReceiver" android:permission="com.google.android.c2dm.permission.SEND">
Which means you need a class called C2DMReceiver that extends C2DMBaseReceiver in the c2dm package. To get implement this, I copied both the c2dm package and C2DMReceiver.java file from the chrometophone-android example over to my project and was able to get a registration id from the C2DM server as intended.
I had the same problem. My solution was moving all of the permissions in my manifest above the application tag.
Things you can check:
1 I noticed is that you are declaring a C2DM permission but don't use it in your application like so:
<uses-permission android:name="com.bilthon.ufrj.permission.C2D_MESSAGE" />
2 If you have a look at the c2dm library you will see that the helper C2DMessaging's register method creates the intent with an additional call to setPackage.
registrationIntent.setPackage("com.google.android.gsf");

Categories

Resources