获取Android手机系统当前界面Activity;(第三方app跳转华为,小米,oppo,vivo的自启动管理)

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/javaFORandroid/article/details/53197378

需求:第三方app跳转华为手机的受保护后台;小米手机的自启动管理;oppo手机的某个app的后台冻结;vivo手机的加速白名单;

执行这个指令 adb shell dumpsys activity top

(要是出现adb用不了,error:unknown host service的解决方法

http://www.360doc.com/content/15/0509/22/23129045_469300718.shtml

执行指令之后的显示

把图片中红线的内容添加到Intent中进行跳转:

Intent intent = new Intent();
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ComponentName comp = null;
if (phoneModel.equals("1")) {//华为
comp = ComponentName
            .unflattenFromString("com.huawei.systemmanager/.optimize.process.ProtectActivity");
} else if (phoneModel.equals("2")) {//小米
comp = ComponentName
            .unflattenFromString("com.miui.securitycenter/com.miui.permcenter.autostart.AutoStartManagementActivity");
} else if (phoneModel.equals("3")) {//vivo
comp = ComponentName
            .unflattenFromString("com.iqoo.secure/.ui.phoneoptimize.AddWhiteListActivity");
} else if (phoneModel.equals("4")) {//oppo
comp = ComponentName
            .unflattenFromString("com.coloros.oppoguardelf/com.coloros.powermanager.fuelgaue.PowerUsageModelActivity");
}
intent.setComponent(comp);
startActivity(intent);

然后就可以测试了;这边的oppo手机只是到了设置中的其他界面?(因为我没有oppo手机);要是本人有的话,可以先把app下载下来。然后在设置中其他界面点击app进入的界面通过指令就可以获取包名和类名

展开阅读全文

[Android UI界面] Activity跳转不成功

04-23

本人学习Android一周,有三个问题烦恼了好几天 网上查了不少资料 研究了很久但没成功 求解答!!rn一,ListView 用了两种方法也跳转不了(点击一下条目出问题has stoped unexpected)。以下贴上代码rnjava源码:rnpackage lin.MytestListView3;rnrnrnrnimport java.util.ArrayList;rnrnimport java.util.HashMap;rnrnimport android.app.Activity;rnrnimport android.content.Intent;rnrnimport android.os.Bundle;rnrnimport android.view.ContextMenu;rnrnimport android.view.MenuItem;rnrnimport android.view.View;rnrnimport android.view.ContextMenu.ContextMenuInfo;rnrnimport android.view.View.OnCreateContextMenuListener;rnrnimport android.widget.AdapterView;rnrnimport android.widget.ListView;rnrnimport android.widget.SimpleAdapter;rnrnimport android.widget.AdapterView.OnItemClickListener;rnrnrnrnpublic class MytestListView3Activity extends Activity rnrn@Overridernrnpublic void onCreate(Bundle savedInstanceState) rnrnsuper.onCreate(savedInstanceState);rnrnsetContentView(R.layout.main);rnrn//绑定Layout里面的ListViewrnrnListView list = (ListView) findViewById(R.id.ListView01);rnrnrnrn//生成动态数组,加入数据rnrnArrayList> listItem = new ArrayList>();rnrnfor(int i=0;i<10;i++)rnrnrnrnHashMap map = new HashMap();rnrnmap.put("ItemImage", R.drawable.checked);//图像资源的IDrnrnmap.put("ItemTitle", "Level "+i);rnrnmap.put("ItemText", "Finished in " +i+" Min 54 Secs, 70 Moves! ");rnrnlistItem.add(map);rnrnrnrn//生成适配器的Item和动态数组对应的元素,这里用SimpleAdapter作为ListView的数据源rnrn//如果条目布局比较复杂,可以继承BaseAdapter来定义自己的数据源。rnrnSimpleAdapter listItemAdapter = new SimpleAdapter(this,listItem,//数据源 rnrnR.layout.listview_item,//ListItem的XML实现rnrn//动态数组与ImageItem对应的子项 rnrnnew String[] "ItemImage","ItemTitle", "ItemText", rnrn//ImageItem的XML文件里面的一个ImageView,两个TextView IDrnrnnew int[] R.id.ItemImage,R.id.ItemTitle,R.id.ItemTextrnrn);rnrnrnrn//添加并且显示rnrnlist.setAdapter(listItemAdapter);rnrnrnrn//添加点击rnrnlist.setOnItemClickListener(new OnItemClickListener() rnrnrnrn//第一种测试方法:rnrn@Overridernrnpublic void onItemClick(AdapterView arg0, View arg1, int arg2,rnrnlong arg3) rnrnsetTitle("点击第"+arg2+"个项目");rnrnrnrn//生成一个Intent对象rnrnIntent intent = new Intent();rnrn//在Intent对象当中添加一个键值对 rnrnintent.putExtra("testIntent", "123");rnrn//设置Intent对象要启动的Activityrnrnintent.setClass(MytestListView3Activity.this, MyIntenttest.class);rnrn//通过Intent对象启动另外一个ActivityrnrnMytestListView3Activity.this.startActivity(intent);rnrnrnrnrnrn/*第二种测试方法switch():rnrn@Override rnrnpublic void onItemClick(AdapterView parent, View view,int position, long id) rnrn rnrn//生成一个Intent对象rnrnIntent intent = new Intent();rnrnswitch(position)rnrnrnrncase 0: intent.setClass(MytestListView3Activity.this, MyIntenttest.class);rnrnbreak;rnrnrnrnMytestListView3Activity.this.startActivity(intent);rnrn */ rnrnrnrn);rnrnrnrn//添加长按点击rnrnlist.setOnCreateContextMenuListener(new OnCreateContextMenuListener() rnrnrnrn@Overridernrnpublic void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo) rnrnmenu.setHeaderTitle("长按菜单-ContextMenu"); rnrnmenu.add(0, 0, 0, "弹出长按菜单0");rnrnmenu.add(0, 1, 0, "弹出长按菜单1"); rnrnrnrn); rnrn rnrnrnrn//长按菜单响应函数rnrn@Overridernrnpublic boolean onContextItemSelected(MenuItem item) rnrnsetTitle("点击了长按菜单里面的第"+item.getItemId()+"个项目"); rnrnreturn super.onContextItemSelected(item);rnrnrnrnrnpackage lin.MytestListView3;rnrnrnrnrnrnimport android.app.Activity;rnrnimport android.content.Intent;rnrnimport android.os.Bundle;rnrnimport android.widget.TextView;rnrnrnrnpublic class MyIntenttest extends Activityrnrnprivate TextView myTextView=null;rnrn@Overridernrnprotected void onCreate(Bundle savedInstanceState) rnrn// TODO Auto-generated method stubrnrnsuper.onCreate(savedInstanceState);rnrnsetContentView(R.layout.jobx);rnrn//Intent intent = getIntent();rnrn//String value = intent.getStringExtra("testIntent");rnrnmyTextView=(TextView)findViewById(R.id.myTextView); rnrn//myTextView.setText("This is my second TestView");rnrn//myTextView.setText(value);rnrnrnrnrnrnrnmain.xmlrnrnrnrnrnrnrnrnrnlistview_item.xmlrnrnrnrnrn rnrnrnrnrnrnrnrnjobx.xmlrnrnrnrnrn rnrnrnrn上面的工程不能从MytestListView3Activity跳转到 MyIntenttest ,应该是我忽略了一些细节吧。(ps:在manifest已经添加了MyIntenttest)rnrn二,自定义的TabHost 在也不能用intent实现跳转,不知道哪里出问题,但如果继承TabActivity 就可以用intent跳转。有什么需要注意的呢?rn以下是代码:rnStudentYard.javarnpackage com.easymorse;rnrnrnrnrnrnimport android.app.Activity;rnrnimport android.app.TabActivity;rnrnimport android.content.Intent;rnrnimport android.os.Bundle;rnrnimport android.view.Window;rnrnimport android.widget.TabHost;rnrnrnrnpublic class StudentYard extends TabActivity rnrnTabHost tabHost; rnrnrnrn@Overridernrnprotected void onCreate(Bundle savedInstanceState) rnrnsuper.onCreate(savedInstanceState);rnrnsetContentView(R.layout.main);rnrnrequestWindowFeature(Window.FEATURE_NO_TITLE);rnrnrnrn//final TabHost tabHost = getTabHost();rnrntabHost = (TabHost)this.findViewById(R.id.tabhost01);rnrntabHost.setup();//调用tabhost.setup()方法初始化tabhostrnrnrnrntabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("教学视频")rnrn.setContent(new Intent(this, TeachfilmList.class)));rnrnrnrntabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("学习文档")rnrn.setContent(new Intent(this, StudydocumentList.class)));rnrnrnrntabHost.addTab(tabHost.newTabSpec("tab3").setIndicator("招聘资讯")rnrn.setContent(new Intent(this, JobList.class)));rnrnrnrnrnrnTeachfilmList.java (ps:这里三个activity 都一样故只贴出来一个activity)rnimport android.app.ListActivity;rnrnimport android.content.Intent;rnrnimport android.os.Bundle;rnrnimport android.view.View;rnrnimport android.widget.ArrayAdapter;rnrnimport android.widget.ListView;rnrnimport android.widget.Toast;rnrnrnrnpublic class TeachfilmList extends ListActivity rnrnprivate String[]texts= new String[] "c1", "c2","c3" ;rnrn@Overridernrnprotected void onCreate(Bundle savedInstanceState) rnrnsuper.onCreate(savedInstanceState);rnrnrnrnthis.setListAdapter(new ArrayAdapter(this,rnrnandroid.R.layout.simple_list_item_1, texts));rnrnrnrnrnrnrnrnrnmain.xmlrnrnrnrnrnrnrnrnrn rnrnrnrnrnrnrnrnrn上面自定义的TabHost 不能实现跳转,如果是继承TabActivity就能实现跳转,为什么呢?rnrn三,我们设置TabHost的头部(标题,图片)和内容 都是在java文件里添加的 如果要修改标题,内容字体颜色等属性能在xml里修改吗?怎么设置属性 ?rnrn上面的三个问题我知道都是很菜的问题,希望有人能帮我解答,感激不尽!!!rn 论坛

没有更多推荐了,返回首页