[aerogear-dev] Android push issue?

Summers Pittman supittma at redhat.com
Mon Jul 29 10:18:30 EDT 2013


On 07/27/2013 09:01 AM, Marc Sluiter wrote:
> Hi all,
>
> I had a further look into Android push, and there is a thing I don't understand,
> maybe there is an issue:
>
> In Registrar.onPostExecute() there are these lines:
>
> ComponentName component = new ComponentName(context, AGPushMessageReceiver.class);
> int status = context.getPackageManager().getComponentEnabledSetting(component);
> if (status == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) {
> 	// register AGPushMessageReceiver
> }
>
> What should this code do? Should it check if a receiver is registered already?
This code is leftover from an experiment in being able to set the 
Broadcast receiver programatically and should probably be excised with 
fire for the reasons you listed.
> If yes, the problem with this is, that the if statement is always true,
> regardless of whether there is a receiver registered in the manifest or not. So
> it registers a second one, if there is already one in the manifest. Tested by
> setting a breakpoint to the receivers onReceive() method, it's called twice for
> each notification.
>
> An alternative way to check if a receiver is registered is this:

>
> String action = "com.google.android.c2dm.intent.RECEIVE";
> Intent intent = new Intent(action);
> List<ResolveInfo> resolveInfos =
> context.getPackageManager().queryBroadcastReceivers(intent,
> PackageManager.GET_INTENT_FILTERS);
> boolean isRegistered = false;
> String receiverName = AGPushMessageReceiver.class.getName();
> for(ResolveInfo resolveInfo : resolveInfos){
> 	if(resolveInfo.activityInfo.name.equals(receiverName)){
> 		isRegistered = true;
> 		break;
> 	}
> }
> if(!isRegistered){
> 	// register AGPushMessageReceiver
> }
>
> I can send a PR if you want to.
>
>
> Furthermore I'm not sure if it really makes sense to register a
> BroadcastReceiver for push notifications programmatically. The reason is, that
> this receiver is tied to the lifecycle of the app. That means after a reboot no
> messages are received until the app is started, and when Android destroys the
> app after some inactive time, no messages will be received anymore too. See the
> note in
> https://developer.android.com/reference/android/content/Context.html#registerReceiver(android.content.BroadcastReceiver,
> android.content.IntentFilter):
> "..the lifetime of such a registered BroadcastReceiver is tied to the object
> that registered it."
> I confirmed this by commenting out the receiver in the PushEE demo app manifest.
>
> What do you think?
I think you are correct.  The code needs to go.
>
> Regards,
>
> Marc
> _______________________________________________
> aerogear-dev mailing list
> aerogear-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/aerogear-dev



More information about the aerogear-dev mailing list