Android app implements feature notes as a system application

Source: Internet
Author: User

1. Disabling StatusBar related functions
Need to add permissions
<uses-permission android:name= "Android.permission.STATUS_BAR" ></uses-permission>
Enum Statusbarcmd {
Disable_expand,
Disable_none,
Disable_recent,
Disable_notification_icons
}

public static void Disablestatusbar (context context, statusbarcmd cmd) {
try {
Object service = Context.getsystemservice ("StatusBar");
class<?> Statusbarmanager = Class.forName ("Android.app.StatusBarManager");
Method disable = Statusbarmanager.getmethod ("Disable", Int.class);
Disable.setaccessible (TRUE);
Field Disable_expand = Statusbarmanager.getfield (Cmd.name ());
Disable_expand.setaccessible (TRUE);
int Disable_code = Disable_expand.getint (Statusbarmanager);
LOG.D ("YYY", "Disable code =" +disable_code);
Disable.invoke (Service,disable_code);
}catch (Exception ex) {
Ex.printstacktrace ();
}
}

2. Code Dynamic Switch Launcher

Require permissions

<uses-permission android:name= "Android.permission.FORCE_STOP_PACKAGES" ></uses-permission>
private void Switchlauncher (Context context,componentname activity) {
Packagemanager pm = Context.getpackagemanager ();
LOG.D ("YYY", "switch Launcher" +activity);
try {
class<?> Packagemanager = Class.forName ("Android.content.pm.PackageManager");
Method replacepreferedactivity = Packagemanager.getmethod ("replacepreferredactivity", Intentfilter.class,int.class , Componentname[].class,componentname.class);
Intentfilter homefilter = new Intentfilter (intent.action_main);
Homefilter.addcategory (Intent.category_home);
Homefilter.addcategory (Intent.category_default);

list<resolveinfo> Resolveinfos = new arraylist<resolveinfo> ();
ComponentName curlauncher = Listhomeactivitys (Context,resolveinfos);
if (Resolveinfos! = null && resolveinfos.size () > 0) {
componentname[] Componentnames = new componentname[resolveinfos.size ()];
for (int i =0; i<resolveinfos.size (); i++) {
Activityinfo Activityinfo = Resolveinfos.get (i). Activityinfo;
if (activityinfo! = null) {
ComponentName cn = New ComponentName (Activityinfo.packagename, activityinfo.name);
Componentnames[i] = cn;
LOG.D ("YYY", "Launcher:" +CN);
}
}
Replacepreferedactivity.setaccessible (TRUE);
Replacepreferedactivity.invoke (pm,homefilter,intentfilter.match_category_empty,componentnames,activity);
Killpackage (Context,curlauncher.getpackagename ());
}else {
LOG.E ("YYY", "Get home Resolve info empty");
}

} catch (Exception e) {
LOG.E ("YYY", "+e");
E.printstacktrace ();
}

}

Private ComponentName Listhomeactivitys (Context context,list<resolveinfo> outs) {
Packagemanager pm = Context.getpackagemanager ();
Object cn = NULL;
try {
class<?> Packagemanager = Class.forName ("Android.content.pm.PackageManager");
Method gethomeactivities = Packagemanager.getmethod ("Gethomeactivities", List.class);
Gethomeactivities.setaccessible (TRUE);
cn = Gethomeactivities.invoke (pm,outs);
}catch (Exception e) {
LOG.E ("YYY", "+e");
E.printstacktrace ();
}
Return (ComponentName) cn;
}

private void Killpackage (Context context,string pkg) {
Activitymanager am = (activitymanager) context.getsystemservice (Context.activity_service);
Am.killbackgroundprocesses (pkg);
}

Android app implements feature notes as a system application

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.