Android small feature set

Source: Internet
Author: User

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 "/>


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.