根据包名打开其他应用。

来源:互联网 发布:openwrt wifi mac 编辑:程序博客网 时间:2024/06/10 06:26

在制作luncher的时候,用的就是这种方法,为luncher添加事件监听器。

调起其他应用,只需要知道manifest中的包名(当然前提是设备中安装了该应用)

 

startActivity(getPackageManager().getLaunchIntentForPackage("com.UCMobile")); 

也可以配合发送广播和接收广播来进行操作,例如发送一条广播之后,接收端收到,进行相应的动作:

public void onReceive(Context context, Intent intent) {            String action = intent.getAction();            if(action.equals(ACTION)){                String str;                str = intent.getStringExtra("flag");<pre name="code" class="java">      if (str.equals("opennav")){                    Intent intent4 = getPackageManager().getLaunchIntentForPackage("com.astrob.activity");                    if (intent4 != null) {                        startActivity(intent4);                    }                }
}

0 0