现在的位置: 首页 > 编程语言 > 正文

使用代码启动其他程序

2018年09月11日 编程语言 ⁄ 共 346字 ⁄ 字号 评论关闭

你要访问其他的程序,那么这个程序要先装在到模拟器或真机上面,因为我们要使用要访问其他程序的包。

简单的访问有以下两种方式(目前只知道这两种):

一、使用Intent的setComponent方法

Intent intent = new Intent();
intent.setComponent(new ComponentName("包名", "包名.主类名"));
intent.setAction(Intent.ACTION_VIEW);
startActivity(intent);

二、使用包管理器

Intent intent = new Intent();
intent = getPackageManager().getLaunchIntentForPackage("包名");
startActivity(intent);

抱歉!评论已关闭.