首先获取包名:
使用aapt //aapt是sdk自带的一个工具,在sdk\builds-tools\目录下
1.以微信为例,命令行中切换到aapt.exe目录执行:aapt dump badging E:\android\weixin531android460.apk
2.运行后的结果如下(仅截取部分):
package: name='com.tencent.mm' versionCode='542' versionName='6.1.0.105_r1085424'
uses-permission:'com.tencent.mm.plugin.permission.READ'
uses-permission:'com.tencent.mm.plugin.permission.WRITE'
uses-permission:'com.tencent.mm.plugin.permission.SEND'
uses-permission:'com.tencent.mm.permission.MM_MESSAGE'
sdkVersion:'10'
targetSdkVersion:'16'
我们可以看到关于微信的很多信息,其中就包括包名,微信的包名为:com.tencent.mm
然后启动代码:
- try {
- PackageManager packageManager = getPackageManager();
- Intent intent=new Intent();
- intent = packageManager.getLaunchIntentForPackage("com.tencent.mm");
- startActivity(intent);
- } catch (Exception e) {
- e.printStackTrace();
- Intent viewIntent = new
- Intent("android.intent.action.VIEW",Uri.parse("http://weixin.qq.com/"));
- startActivity(viewIntent);
- }
如果手机上安装了微信,就打开微信的主界面,如果没有安装就打开一个浏览器去下载!!!
转载地址:http://blog.csdn.net/lovexieyuan520/article/details/44301753