当前位置: 移动技术网 > IT编程>移动开发>Android > Android Intent启动别的应用实现方法

Android Intent启动别的应用实现方法

2019年07月24日  | 移动技术网IT编程  | 我要评论

八零军嫂是神医,用飞信打电话要钱吗,搁浅阴霾娃娃

我们知道intent的应用,可以启动别一个activity,那么是否可以启动别外的一个应用程序呢,答案是可以的。

1、首先我们新建一个android应用,名为anotherpro,此应用什么内容都没有,用于被另外一个程序打开。

2、新建一个工程用于打开上面的应用,程序界面如下

3、修改程序代码,在oncreate中添加如下代码

anotherpro = (button) findviewbyid(r.id.startanotherpro);calendar = (button) findviewbyid(r.id.startcalendar);anotherpro.setonclicklistener(new onclicklistener() {@overridepublic void onclick(view v) {intent intent = new intent();intent.setcomponent(new componentname("com.anotherpro", "com.anotherpro.mainactivity"));startactivity(intent);}});calendar.setonclicklistener(new onclicklistener() {@overridepublic void onclick(view v) {intent intent = new intent();intent.setcomponent(new componentname("com.android.calendar", "com.android.calendar.launchactivity"));startactivity(intent);}});
intent.setcomponent(new componentname(packagename, mainactivityname));// 第一个参数为应用程序包名,第二个参数为程序启动的activity

 运行程序,点击anotherpro将会打开第一个应用;

 点击calendar将会打开系统的日历应用。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网