在我的onCreate()中我做了这个检查:
//
// check if we have a PDF viewer, else bad things happen
//
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setType("application/pdf");
List<ResolveInfo> intents = getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
if (intents == null || intents.size() == 0) {
// display message then...
finish();
}
Run Code Online (Sandbox Code Playgroud)
在我的HTC Desire上,即使我有Adobe的PDF查看器,也不会返回匹配项.回答这个问题android:使用内置的pdf查看器从我的应用程序打开一个pdf,提到Adobe可能没有任何公共意图,所以上面的检查显然不会返回任何内容.
任何人都可以验证您是否应该从意图启动Acrobat,或者是否有其他方法或PDF查看器可以使用.
实际用例是下载发票副本并使用以下代码将其存储在本地存储中:
URL url = new URL(data);
InputStream myInput = url.openConnection().getInputStream();
FileOutputStream fos = openFileOutput(fname, Context.MODE_WORLD_READABLE);
// transfer bytes from the input file to the output file
byte[] buffer = new byte[8192];
int length;
while …Run Code Online (Sandbox Code Playgroud)