Created
September 30, 2011 19:08
-
-
Save jmif/1254688 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.midwestfleet.receivers; | |
import android.accounts.Account; | |
import android.accounts.AccountManager; | |
import android.app.PendingIntent; | |
import android.content.BroadcastReceiver; | |
import android.content.Context; | |
import android.content.Intent; | |
/** | |
* Simple receiver to start the Google C2DM service registration | |
* This is encapsulated in a receiver so that we can call it using alarms | |
* multiple times in case an internet connection is not available. | |
* | |
* @author jamifsud | |
* | |
*/ | |
public class RegisterC2DMReceiver extends BroadcastReceiver { | |
public static final String BROADCAST_ACTION = "com.midwestfleet.receivers.RegisterC2DMReceiver.receive"; | |
@Override | |
public void onReceive(Context c, Intent i) { | |
String email = null; | |
// Get the devices midwestfleet.com email address | |
Account[] accounts = AccountManager.get(c).getAccountsByType("com.google"); | |
for (Account account : accounts) { | |
if (account.name.endsWith("midwestfleet.com")) { | |
email = account.name; | |
} | |
} | |
// Fire off the intent | |
Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER"); | |
registrationIntent.putExtra("app", PendingIntent.getBroadcast(c, 0, new Intent(), 0)); // boilerplate | |
registrationIntent.putExtra("sender", email); | |
c.startService(registrationIntent); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment