[英]I can not open a PDF in my android application
我做了一個android應用程序。 我創建了一個可擴展列表,當我單擊一個孩子時,我想打開一個PDF。 PDF未打開,將顯示一條消息,內容為no_application_found(“ PDF無法打開”)中的內容。 打開PDF的代碼是:
public boolean onChildClick (
ExpandableListView parent,
View v,
int groupPosition,
int childPosition,
long id) {
Log.d( LOG_TAG, "onChildClick: " + childPosition );
File file = new File("http://www.ratt.ro/grafice/e2-a.pdf");
Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setDataAndType(path, getString(R.string.application_type));
try
{
startActivity(intent);
}
catch (ActivityNotFoundException e)
{
Toast.makeText(ElistCBox.this,
getString(R.string.no_application_found),
Toast.LENGTH_SHORT).show();
}
return false;
}
這是您在網絡視圖中打開PDF的方式:
webview.loadUrl("http://docs.google.com/gview?embedded=true&url=http://www.ratt.ro/grafice/e2-a.pdf");
這是我在閱讀器中打開PDF文件的代碼,如果用戶沒有任何pdf閱讀器,則會打開指向Google Play的鏈接以供下載:
void openpdf (String filename)
{
String loc = "/sdcard/";
File file = new File(loc+filename);
Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try {
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), "No pdf reader installed", Toast.LENGTH_SHORT).show();
Intent market = new Intent(Intent.ACTION_VIEW);
market.setData(Uri.parse("market://details?id=com.adobe.reader"));
startActivity(market);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.