【发布时间】:2012-09-26 06:14:41
【问题描述】:
我的手机上安装了 Dictionary.com 应用程序。 我正在创建另一个应用程序,想知道如何使用 Intent 与 Dictionary 应用程序进行交互。
如果有什么办法请告诉我
【问题讨论】:
标签: android android-intent dictionary
我的手机上安装了 Dictionary.com 应用程序。 我正在创建另一个应用程序,想知道如何使用 Intent 与 Dictionary 应用程序进行交互。
如果有什么办法请告诉我
【问题讨论】:
标签: android android-intent dictionary
您可以通过这种方式从您的应用程序中调用您的字典应用程序..
这里 com.example.package.ActivityToStart 定义了您的字典应用程序
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName("com.example.package", "com.example.package.ActivityToStart");
startActivity(intent);
另一个最好的方法是
try{
PackageManager pm = getPackageManager();
Intent intent = pm.getLaunchIntentForPackage("com.example.package");
startActivity(intent);
}catch (Exception e) {
e.printStackTrace();
}
如果您不知道词典应用程序的包名,请查看this
【讨论】:
try {} catch {}第二个选项,以防数据包不存在(NameNotFoundException)