Collection of some small Android feature sets
This prevents our applications from appearing in the latest taskbar (Note: it is not the task manager ).
<! -- Add Property --> Android: excludefromrecents = "true"
Obtain all home applications installed on your mobile phone
//private List<String> getHomes() { // List<String> packages = new ArrayList<String>(); // PackageManager packageManager = mservice.getPackageManager();// Intent intent = new Intent(Intent.ACTION_MAIN); // intent.addCategory(Intent.CATEGORY_HOME); // List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent, // PackageManager.MATCH_DEFAULT_ONLY);// for(ResolveInfo info : resolveInfo){// packages.add(info.activityInfo.packageName); // } // return packages; //}
Listen to the Home key, which can be used when needed
HomeKeyEventBroadCastReceiver receiver = new HomeKeyEventBroadCastReceiver();registerReceiver(receiver, new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
Public class homekeyeventbroadcastreceiver extends broadcastreceiver {static final string tag = "homekeyeventbroadcastreceiver"; static final string system_reason = "reason"; static final string system_home_key = "homekey "; // Home Key static final string system_recent_apps = "recentapps"; // long home key @ override public void onreceive (context, intent) {string action = intent. getaction (); If (action. Equals (intent. action_close_system_dialogs) {string reason = intent. getstringextra (system_reason); If (reason! = NULL) {If (reason. equals (system_home_key) {// HOME key processing point string PK = getcurrentpk (context); log. I (TAG, "PK:" + PK); log. I (TAG, "Home Key");} else if (reason. equals (system_recent_apps) {// long home key processing point log. I (TAG, "Long Home Key") ;}}} private string getcurrentpk (context) {activitymanager mactivitymanager = (activitymanager) context. getsystemservice (context. activity_service); List <runningtaskinfo> RRTI = mactivitymanager. getrunningtasks (1); Return rrsps. get (0 ). topactivity. getpackagename ();}}
Create a receiver in the new version to receive the installation and uninstallation of the mobile app (you can listen to the uninstallation of the old version)
Publicclass pkinstallreceiver extends broadcastreceiver {@ override public void onreceive (context, intent) {If (intent. getaction (). equals ("android. intent. action. package_added ") {string packagename = intent. getdatastring (). substring (8); system. out. println ("installation:" + packagename + "package name program");} // receives the unmounted broadcast if (intent. getaction (). equals ("android. intent. action. package_removed ") {string packagename = intent. getdatastring (). substring (8); system. out. println ("Uninstall:" + packagename + "package name program"); intent newintent = new intent (); newintent. setclassname (packagename, packagename + ". autostartprotestactivity "); newintent. setaction ("android. intent. action. main "); newintent. addcategory ("android. intent. category. launcher "); newintent. setflags (intent. flag_activity_new_task); context. startactivity (newintent) ;}} androidmanifest. XML for configuration // javaser <javaser Android: Name = "com. justsy. LPI. aggreger. pkinstallreceiver "Android: Label =" @ string/app_name "> <intent-filter> <action Android: Name =" android. intent. action. package_added "/> <action Android: Name =" android. intent. action. package_removed "/> <data Android: Scheme =" package "/> </intent-filter> </Cycler> // permission <uses-Permission Android: Name =" android. permission. restart_packages "/> <uses-Permission Android: Name =" android. permission. receive_boot_completed "/>