在一个Android应用程序中启动另一个程序(微信)

时间:2022-08-29 16:21:03

     其实很简单,只是几句代码


    try { 

/*判断微信是否安装*/

if((MyActivity.this.getPackageManager().getPackageInfo("com.tencent.mm", 64)) == null)
{
Toast.makeText(MyActivity.this, "微信未安装!", Toast.LENGTH_SHORT).show();
return;
}

} catch (NameNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
Toast.makeText(MyActivity.this, "微信未安装!", Toast.LENGTH_SHORT).show();
return;
}
        try {
        MyActivity.this.startActivity(MyActivity.this.getPackageManager().getLaunchIntentForPackage("com.tencent.mm"));//打开微信,com.tencent.mm是微信的包名
        Log.i(TAG, "start weixin");
} catch (Exception e) {
// TODO: handle exception
Toast.makeText(MyActivity.this, "请检查是否安装微信!", Toast.LENGTH_SHORT).show();

}