SD Card Listener:
Packageorg.dreamtech.sdstate;ImportAndroid.content.BroadcastReceiver;ImportAndroid.content.Context;Importandroid.content.Intent; Public classSdcardstatereceiverextendsBroadcastreceiver {@Override Public voidOnReceive (Context context, Intent Intent) {//Get Event TypeString action =intent.getaction (); if("Android.intent.action.MEDIA_MOUNTED". Equals (action)) { //SD card Mount}Else if("Android.intent.action.MEDIA_UNMOUNTED". Equals (action)) { //SD Card Uninstall } }}
Configuring receiver
<receiverAndroid:name= "Org.dreamtech.sdstate.SdcardStateReceiver"> <Intent-filter> <ActionAndroid:name= "Android.intent.action.MEDIA_MOUNTED"/> <ActionAndroid:name= "android.intent.action."/> <!--the constraint type is called file because the data type stored in the SD is file - <DataAndroid:scheme= "File"/> </Intent-filter> </receiver>
SMS Listener:
PackageOrg.dreamtech.smslistener;ImportAndroid.content.BroadcastReceiver;ImportAndroid.content.Context;Importandroid.content.Intent;ImportAndroid.telephony.SmsMessage; Public classSmslistenerreceiverextendsBroadcastreceiver {@Override Public voidOnReceive (Context context, Intent Intent) {object[] objects= (object[]) Intent.getextras (). Get ("PDUs"); for(Object object:objects) {smsmessage smsmessage= SMSMESSAGE.CREATEFROMPDU ((byte[]) object); String MessageBody=Smsmessage.getmessagebody (); String Address=smsmessage.getoriginatingaddress (); System.out.println ("SMS Content:" + MessageBody + "# # #" + "from" +address); } }}
Note Configuration and Permissions:
<?XML version= "1.0" encoding= "Utf-8"?><Manifestxmlns:android= "Http://schemas.android.com/apk/res/android" Package= "Org.dreamtech.smslistener"Android:versioncode= "1"Android:versionname= "1.0" > <USES-SDKandroid:minsdkversion= "8"android:targetsdkversion= "+" /> <uses-permissionAndroid:name= "Android.permission.RECEIVE_SMS"/> <ApplicationAndroid:allowbackup= "true"Android:icon= "@drawable/ic_launcher"Android:label= "@string/app_name"Android:theme= "@style/apptheme" > <ActivityAndroid:name= "Org.dreamtech.smslistener.MainActivity"Android:label= "@string/app_name" > <Intent-filter> <ActionAndroid:name= "Android.intent.action.MAIN" /> <categoryAndroid:name= "Android.intent.category.LAUNCHER" /> </Intent-filter> </Activity> <receiverAndroid:name= "Org.dreamtech.smslistener.SmsListenerReceiver"> <Intent-filter> <ActionAndroid:name= "Android.provider.Telephony.SMS_RECEIVED"/> </Intent-filter> </receiver> </Application></Manifest>
To uninstall the installation listener:
Packageorg.dreamtech.appstate;ImportAndroid.content.BroadcastReceiver;ImportAndroid.content.Context;Importandroid.content.Intent; Public classAppstatereceiverextendsBroadcastreceiver {@Override Public voidOnReceive (Context context, Intent Intent) {String action=intent.getaction (); if("Android.intent.action.PACKAGE_INSTALL". Equals (action)) { //app installation (although present, but not actually called)}Else if("Android.intent.action.PACKAGE_ADDED". Equals (action)) { //Application Installation}Else if("Android.intent.action.PACKAGE_REMOVED". Equals (action)) { //App Uninstall } }}
Configuration:
<?XML version= "1.0" encoding= "Utf-8"?><Manifestxmlns:android= "Http://schemas.android.com/apk/res/android" Package= "Org.dreamtech.appstate"Android:versioncode= "1"Android:versionname= "1.0" > <USES-SDKandroid:minsdkversion= "8"android:targetsdkversion= "+" /> <ApplicationAndroid:allowbackup= "true"Android:icon= "@drawable/ic_launcher"Android:label= "@string/app_name"Android:theme= "@style/apptheme" > <ActivityAndroid:name= "Org.dreamtech.appstate.MainActivity"Android:label= "@string/app_name" > <Intent-filter> <ActionAndroid:name= "Android.intent.action.MAIN" /> <categoryAndroid:name= "Android.intent.category.LAUNCHER" /> </Intent-filter> </Activity> <receiverAndroid:name= "Org.dreamtech.appstate.AppStateReceiver" > <Intent-filter> <ActionAndroid:name= "Android.intent.action.PACKAGE_INSTALL" /> <ActionAndroid:name= "Android.intent.action.PACKAGE_ADDED" /> <ActionAndroid:name= "Android.intent.action.PACKAGE_REMOVED" /> <!--Note Configuration Constraints - <DataAndroid:scheme= "Package" /> </Intent-filter> </receiver> </Application></Manifest>
Android Development: A variety of applications for broadcasting