所以,我在这一行上有错误:
getActivity().copyFile(in, out);
我的所有代码:
AssetManager assetManager = getActivity().getAssets();
InputStream in = null;
OutputStream out = null;
File file = new File(getActivity().getFilesDir(), "GimnazistoKnygele[KSG].pdf");
try {
in = assetManager.open("GimnazistoKnygele[KSG].pdf");
out = getActivity().openFileOutput(file.getName(), Context.MODE_WORLD_READABLE);
getActivity().copyFile(in, out);
in.close();
in = null;
out.flush();
out.close();
out = null;
} catch (Exception e) {
Log.e("tag", e.getMessage());
}
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(
Uri.parse("file://" + getActivity().getFilesDir() + "/GimnazistoKnygele[KSG].pdf"),
"application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
getActivity().startActivity(intent);
} catch (ActivityNotFoundException e) {
Toast.makeText(getActivity(),
"Jūsų įrenginyje nėra PDF tvarkyklės!", Toast.LENGTH_LONG).show();
}
我尝试用片段做的所有这一切。感谢您的支持! :)