Broadcast intents android app action ACTIONPASSWORDCHANGED android app
Broadcast intents
• • • • • • • • • android. app. action. ACTION_PASSWORD_CHANGED android. app. action. ACTION_PASSWORD_FAILED android. app. action. ACTION_PASSWORD_SUCCEEDE D android. app. action. DEVICE_ADMIN_DISABLE_REQU ESTED android. app. action. DEVICE_ADMIN_ENABLED android. bluetooth. a 2 dp. action. SINK_STATE_CHANG ED android. bluetooth. adapter. action. DISCOVERY_FINIS HED android. bluetooth. adapter. action. DISCOVERY_STAR TED android. bluetooth. adapter. action. LOCAL_NAME_CH ANGED android. bluetooth. adapter. action. SCAN_MODE_CH ANGED android. bluetooth. adapter. action. STATE_CHANGED android. bluetooth. device. action. ACL_CONNECTED android. bluetooth. device. action. ACL_DISCONNECTE D android. bluetooth. device. action. ACL_DISCONNECT_ REQUESTED android. bluetooth. device. action. BOND_STATE_CHA NGED android. bluetooth. device. action. CLASS_CHANGED android. bluetooth. device. action. FOUND android. bluetooth. device. action. NAME_CHANGED android. bluetooth. devicepicker. action. DEVICE_SELE CTED android. bluetooth. devicepicker. action. LAUNCH android. bluetooth. headset. action. AUDIO_STATE_CH ANGED android. bluetooth. headset. action. STATE_CHANGED android. intent. action. ACTION_POWER_CONNECTED android. intent. action. ACTION_POWER_DISCONNECT ED android. intent. action. ACTION_SHUTDOWN android. intent. action. AIRPLANE_MODE android. intent. action. BATTERY_CHANGED android. intent. action. BATTERY_LOW android. intent. action. BATTERY_OKAY android. intent. action. BOOT_COMPLETED android. intent. action. CAMERA_BUTTON android. intent. action. CONFIGURATION_CHANGED • • • • • • • • • android. intent. action. DATA_SMS_RECEIVED android. intent. action. DATE_CHANGED android. intent. action. DEVICE_STORAGE_LOW android. intent. action. DEVICE_STORAGE_OK android. intent. action. DOCK_EVENT android. intent. action. EXTERNAL_APPLICATIONS_AV AILABLE android. intent. action. EXTERNAL_APPLICATIONS_UN AVAILABLE android. intent. action. GTALK_CONNECTED android. intent. action. GTALK_DISCONNECTED android. intent. action. HEADSET_PLUG android. intent. action. INPUT_METHOD_CHANGED android. intent. action. LOCALE_CHANGED android. intent. action. MANAGE_PACKAGE_STORAGE android. intent. action. MEDIA_BAD_REMOVAL android. intent. action. MEDIA_BUTTON android. intent. action. MEDIA_CHECKING android. intent. action. MEDIA_EJECT android. intent. action. MEDIA_MOUNTED android. intent. action. MEDIA_NOFS android. intent. action. MEDIA_REMOVED android. intent. action. MEDIA_SCANNER_FINISHED android. intent. action. MEDIA_SCANNER_SCAN_FILE android. intent. action. MEDIA_SCANNER_STARTED android. intent. action. MEDIA_SHARED android. intent. action. MEDIA_UNMOUNTABLE android. intent. action. MEDIA_UNMOUNTED android. intent. action. NEW_OUTGOING_CALL android. intent. action. PACKAGE_ADDED android. intent. action. PACKAGE_CHANGED android. intent. action. PACKAGE_DATA_CLEARED android. intent. action. PACKAGE_INSTALL android. intent. action. PACKAGE_REMOVED android. intent. action. PACKAGE_REPLACED • • • • • • • • • android. intent. action. PACKAGE_RESTARTED android. intent. action. PHONE_STATE android. intent. action. PROVIDER_CHANGED android. intent. action. REBOOT android. intent. action. SCREEN_OFF android. intent. action. SCREEN_ON android. intent. action. TIMEZONE_CHANGED android. intent. action. TIME_SET android. intent. action. TIME_TICK android. intent. action. UID_REMOVED android. intent. action. UMS_CONNECTED android. intent. action. UMS_DISCONNECTED android. intent. action. USER_PRESENT android. intent. action. WALLPAPER_CHANGED android. media. AUDIO_BECOMING_NOISY android. media. RINGER_MODE_CHANGED android. media. SCO_AUDIO_STATE_CHANGED android. media. VIBRATE_SETTING_CHANGED android. media. action. CLOSE_AUDIO_EFFECT_CONT ROL_SESSION android. media. action. OPEN_AUDIO_EFFECT_CONTR OL_SESSION android. net. conn. BACKGROUND_DATA_SETTING_C HANGED android. net. wifi. NETWORK_IDS_CHANGED android. net. wifi. RSSI_CHANGED android. net. wifi. SCAN_RESULTS android. net. wifi. STATE_CHANGE android. net. wifi. WIFI_STATE_CHANGED android. net. wifi. supplicant. CONNECTION_CHANGE android. net. wifi. supplicant. STATE_CHANGE android. provider. Telephony. SIM_FULL android. provider. Telephony. SMS_RECEIVED android. provider. Telephony. SMS_REJECTED android. provider. Telephony. WAP_PUSH_RECEIVED android. speech. tts. TTS_QUEUE_PROCESSING_COMP LETED android. speech. tts. engine. TTS_DATA_INSTALLED Complete list depends on API version and is found in platform /data/broadcast_actions. txt
Interesting broadcast intents • android. intent. action. PHONE_STATE • android. intent. action. REBOOT • • android. intent. action. ACTION_POWER_CONNECTED android. intent. action. ACTION_POWER_DISCONNECTED • android. intent. action. BATTERY_CHANGED • • android. intent. action. SCREEN_OFF android. intent. action. SCREEN_ON • • • android. intent. action. BATTERY_LOW android. intent. action. BATTERY_OKAY android. intent. action. BOOT_COMPLETED • android. intent. action. TIME_TICK • Every minute • android. intent. action. CAMERA_BUTTON • • • android. intent. action. UMS_CONNECTED android. intent. action. UMS_DISCONNECTED For checking when usb is connected • android. intent. action. DATA_SMS_RECEIVED • android. intent. action. USER_PRESENT • When user unlocks the screen. Note that SCREEN_ON is just for when the screen is on. But the screen might still be locked. This event is when the screen is unlocked • android. intent. action. HEADSET_PLUG • • android. media. RINGER_MODE_CHANGED android. media. VIBRATE_SETTING_CHANGED • android. intent. action. NEW_OUTGOING_CALL • android. net. wifi…. • android. provider. Telephony. SMS_RECEIVED
• • Make new app Track. Device. Usage Make new class called Device. Usage. Intent. Receiver extends Broadcast. Receiver – • In on. Receive, add – • Note broadcast receivers must complete their execution in 10 seconds. If extensive process is needed, start a thread. Log. e("GOTIT", "Got : "+intent. get. Action()); Back in main activity – Add member variable • – In on. Create add • • • – public Device. Usage. Intent. Receiver device. Usage. Intent. Receiver = new Device. Usage. Intent. Receiver(); register. Receiver(device. Usage. Intent. Receiver, new Intent. Filter("android. intent. action. HEADSET_PLUG")); register. Receiver(device. Usage. Intent. Receiver, new Intent. Filter("android. intent. action. SCREEN_OFF")); register. Receiver(device. Usage. Intent. Receiver, new Intent. Filter("android. intent. action. SCREEN_ON")); register. Receiver(device. Usage. Intent. Receiver, new Intent. Filter("android. intent. action. ACTION_POWER_DISCONNECTED")); register. Receiver(device. Usage. Intent. Receiver, new Intent. Filter("android. intent. action. ACTION_POWER_CONNECTED")); register. Receiver(device. Usage. Intent. Receiver, new Intent. Filter("android. intent. action. USER_PRESENT")); Add new function (this is needed so that when your app dies, the OS is not still trying to send it intents) • • @Override public void on. Destroy() { – – • • Run it – • Note: you might need to set permissions! Try opening the browser and check for screen on/off events – • } super. on. Pause(); unregister. Receiver(device. Usage. Intent. Receiver); They still show However, to catch events when your app is not in the foreground, you should use a service
Send information back to Activity • In Track. Device. Usage. Activity, add – public Device. Usage. Info. Receiver device. Usage. Info. Receiver = new Device. Usage. Info. Receiver(); – public class Device. Usage. Info. Receiver extends Broadcast. Receiver { • @Override • public void on. Receive(Context context, Intent intent) { • } • – Log. e("app", "got: "+intent. get. Extras(). get. String("Event. Name")); – } At the end of Device. Usage. Intent. Receiver. on. Receive, after Log. e("GOTIT", "Got : "+intent. get. Action()); , add • • • Intent broadcast=new Intent("edu. udel. eleg 454. Receive. Device. Usage. Info"); broadcast. put. Extra("Event. Name", intent. get. Action()); context. send. Broadcast(broadcast); • Run – The activity still receives messages when app is not in the foreground
- Slides: 5