Created
January 7, 2018 10:39
-
-
Save ahmedyehya92/d41363334b8b1381a2f5cb3bd4ebad6e to your computer and use it in GitHub Desktop.
#103 implementing Broadcast Reciever
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
public class LifeformDetectedReceiver | |
extends BroadcastReceiver { | |
public final static String EXTRA_LIFEFORM_NAME | |
= “EXTRA_LIFEFORM_NAME”; | |
public final static String EXTRA_LATITUDE = “EXTRA_LATITUDE”; | |
public final static String EXTRA_LONGITUDE = “EXTRA_LONGITUDE”; | |
public static final String | |
ACTION_BURN = “com.paad.alien.action.BURN_IT_WITH_FIRE”; | |
public static final String | |
NEW_LIFEFORM = “com.paad.alien.action.NEW_LIFEFORM”; | |
@Override | |
public void onReceive(Context context, Intent intent) { | |
// Get the lifeform details from the intent. | |
Uri data = intent.getData(); | |
String type = intent.getStringExtra(EXTRA_LIFEFORM_NAME); | |
double lat = intent.getDoubleExtra(EXTRA_LATITUDE, 0); | |
double lng = intent.getDoubleExtra(EXTRA_LONGITUDE, 0); | |
Location loc = new Location(“gps”); | |
loc.setLatitude(lat); | |
loc.setLongitude(lng); | |
if (type.equals(“facehugger”)) { | |
Intent startIntent = new Intent(ACTION_BURN, data); | |
startIntent.putExtra(EXTRA_LATITUDE, lat); | |
startIntent.putExtra(EXTRA_LONGITUDE, lng); | |
context.startService(startIntent); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment