按键精灵手机版可以通过
RunApp "com.tencent.mm", ".plugin.sns.ui.SnsTimeLineUI"
直接打开微信朋友圈
我尝试用
ComponentName cmp = new ComponentName("com.tencent.mm","com.tencent.mm.plugin.sns.ui.SnsTimeLineUI");
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setComponent(cmp);
startActivity(intent);
结果获得以下错误
09-15 13:15:53.087 11188-11188/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.lee.myapplication, PID: 11188
java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.VIEW cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.tencent.mm/.plugin.sns.ui.SnsTimeLineUI } from ProcessRecord{42ec77e8 11188:com.example.lee.myapplication/u0a103} (pid=11188, uid=10103) not exported from uid 10092
at android.os.Parcel.readException(Parcel.java:1472)
at android.os.Parcel.readException(Parcel.java:1426)
at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:2185)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1425)
at android.app.Activity.startActivityForResult(Activity.java:3476)
at android.app.Activity.startActivityForResult(Activity.java:3437)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:748)
at android.app.Activity.startActivity(Activity.java:3679)
at android.app.Activity.startActivity(Activity.java:3647)
at com.example.lee.myapplication.MainActivity$1.onClick(MainActivity.java:70)
at android.view.View.performClick(View.java:4469)
at android.view.View$PerformClick.run(View.java:18807)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5315)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:836)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652)
at dalvik.system.NativeStart.main(Native Method)
Only when the Activity declares that it can handle certain intent actions, the third-party app can start it through the intent.
Declare via intent filter in configuration file:
When you know the package name and class name, you can start the third-party activity like this:
It’s okay to do this. But if it is not declared in the manifest, startActivity will cause a crash. You can write two apps as a test, adding and removing intent statements.
PS: The launcher activity of a third-party app can be started through the package name. When I tried to start WeChat, it failed for an unknown reason.
Like. My problem was solved and I can enter WeChat directly
startActivity(getPackageManager().getLaunchIntentForPackage("com.tencent.mm"));
. But whyWill an error be reported?