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")));
}
它总是进入捕获范围。我不知道我做错了什么
答案 0 :(得分:0)
试试这个:
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();
}
}
}
答案 1 :(得分:0)
这应该有所帮助:
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = "netsh";
psi.UseShellExecute = false;
psi.RedirectStandardError = true;
psi.RedirectStandardOutput = true;
psi.Arguments = "SOME_ARGUMENTS";
Process proc = Process.Start(psi);
proc.WaitForExit();
string errorOutput = proc.StandardError.ReadToEnd();
string standardOutput = proc.StandardOutput.ReadToEnd();
if (proc.ExitCode != 0)
throw new Exception("netsh exit code: " + proc.ExitCode.ToString() + " " + (!string.IsNullOrEmpty(errorOutput) ? " " + errorOutput : "") + " " + (!string.IsNullOrEmpty(standardOutput) ? " " + standardOutput : ""));
答案 2 :(得分:0)
您可以尝试:
Intent intent = new Intent();
intent.setPackage("package**name");
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(intent);
并且,您应该在调用的应用程序清单中添加到此行:
<intent-filter>
...
<category android:name="android.intent.category.CATEGORY_DEFAULT" />
</intent-filter>