Overview
因为需求所以贴出该代码,该源码需要系统共享,且开源板子上才能安装,其次需要将编译的apk进行platform签名,仅仅是记录一下开发过程.
Public class mainactivity extends appcompatactivity implements View . Onclicklistener { PrivateObject Statusbarmanagerservice;PrivateMethod methoddisable;PrivateTextView Tvinfo;//Screenpinning_mode_flag = Statusbarmanager.disable_none// | Statusbarmanager.disable_expand// | Statusbarmanager.disable_notification_icons// | Statusbarmanager.disable_notification_alerts// // | Statusbarmanager.disable_clock// // | Statusbarmanager.disable_system_info// | Statusbarmanager.disable_home// | Statusbarmanager.disable_search// | Statusbarmanager.disable_back// | statusbarmanager.disable_recent; Private Final Static intScreenpinning_mode_flag =57081856;Private Final Static intNormal_mode_flag =0;Private Final Static intScreenpinning_mode_with_back_flag =52887552;Private Final Static intDate_settings_request =0;@Override protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate); Setcontentview (R.layout.activity_main); Toolbar Toolbar = (Toolbar) Findviewbyid (R.id.toolbar); Setsupportactionbar (toolbar); Floatingactionbutton fab = (Floatingactionbutton) Findviewbyid (R.id.fab); Fab.setonclicklistener (NewView.onclicklistener () {@Override Public void OnClick(View view) {Snackbar.make (view,"Replace with your own action", Snackbar.length_long). Setaction ("Action",NULL). Show (); } }); Tvinfo = (TextView) Findviewbyid (r.id.tv_info);//Get Android @hide class Android.app.StatusBarManager by reflection. Try{//Reflection Get status bar managerClass Clsstatusbarmanager = Class.forName ("Android.app.StatusBarManager"); Context AppContext = Getapplicationcontext ();if(AppContext! =NULL) {Statusbarmanagerservice = Appcontext.getsystemservice ("StatusBar"); Methoddisable = Clsstatusbarmanager.getmethod ("Disable",int. Class); } }Catch(ClassNotFoundException e) {Reflectionerror (e); }Catch(Nosuchmethodexception e) {Reflectionerror (e); } }Private void Reflectionerror(Exception ex) {Tvinfo.setbackgroundcolor (color.red); Tvinfo.settext ("Reflection Error:"+ ex.tostring ()); }Private void Disablestatusbar(intFlag) {Try{//implementation of the core.Methoddisable.invoke (Statusbarmanagerservice, flag); }Catch(Illegalaccessexception e) {Reflectionerror (e); }Catch(InvocationTargetException e) {Reflectionerror (e); } }@Override Public void OnClick(View v) {Switch(V.getid ()) { CaseR.id.bt_pin: {disablestatusbar (Screenpinning_mode_flag); Break; } CaseR.id.bt_unpin: {disablestatusbar (Normal_mode_flag); Break; } } }@Override Public Boolean Oncreateoptionsmenu(Menu menu) {//inflate the menu; This adds items to the action bar if it is present.Getmenuinflater (). Inflate (R.menu.menu_main, menu);return true; }@Override Public Boolean onoptionsitemselected(MenuItem Item) {//Handle Action Bar item clicks here. The Action Bar would //automatically handle clicks on the Home/up button, so long //As you specify a parent activity in Androidmanifest.xml. intid = item.getitemid ();//noinspection simplifiableifstatement if(id = = r.id.action_settings) {//Enable Back button to return from SettingsDisablestatusbar (Screenpinning_mode_with_back_flag); Startactivityforresult (NewIntent (settings.action_date_settings), date_settings_request);return true; }return Super. onoptionsitemselected (item); }protected void Onactivityresult(intRequestcode,intResultCode, Intent data) {if(Requestcode = = date_settings_request) {//Disable Back button when returning from SettingsDisablestatusbar (Screenpinning_mode_flag); } }}
Finally, you need to add the configuration file:xml
android:sharedUserId="android.uid.system"
Android Disable status bar dropdown