[英]How can I open an android application using another application with intent?
try {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("com.xxx.applicationname"));
startActivity(intent);
} catch(Exception e) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.facebook.com")));
}
it always enter catch scope. 它总是进入捕获范围。 I don't know where I am doing wrong
我不知道我在哪里做错了
Try this: 尝试这个:
protected void launchApp(String packageName) {
Intent mIntent = getPackageManager().getLaunchIntentForPackage(packageName);
if (mIntent != null) {
try {
startActivity(mIntent);
} catch (ActivityNotFoundException err) {
Toast t = Toast.makeText(getApplicationContext(),
"Not FOund", Toast.LENGTH_SHORT);
t.show();
}
}
}
This should help: 这应该有助于:
Intent intent = getActivity().getPackageManager().getLaunchIntentForPackage("com.xxx.app");
if (intent != null)
startActivity(intent);
else
Toast.makeText(getActivity(), "app is not installed", Toast.LENGTH_SHORT).show();
You can try that: 您可以尝试:
Intent intent = new Intent();
intent.setPackage("package**name");
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(intent);
and also, you should add to this line in called application manifest: 并且,您应该在被调用的应用清单中添加以下内容:
<intent-filter>
...
<category android:name="android.intent.category.CATEGORY_DEFAULT" />
</intent-filter>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.