我想从我的Android应用程序中启动已安装的软件包.我假设有可能使用意图,但我找不到这样做的方法.有链接,在哪里可以找到信息?
现在我正在开发一个应用程序.通过我的应用程序用户可以阅读pdf文件,如果没有pdf阅读器,那么我的应用程序将自动从网站安装它.这是我用来阅读pdf文件的代码.
File file = new File("/sdcard/sample.pdf");
PackageManager packageManager = getPackageManager();
Intent testIntent = new Intent(Intent.ACTION_VIEW);
testIntent.setType("application/pdf");
List list = packageManager.queryIntentActivities(testIntent, PackageManager.MATCH_DEFAULT_ONLY);
if (list.size() > 0 && file.isFile()) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
Uri uri = Uri.fromFile(file);
intent.setDataAndType(uri, "application/pdf");
startActivity(intent);
}
Run Code Online (Sandbox Code Playgroud)
我的怀疑是: