2013-09-27 90 views
0

我想從pdfviewer中的URL打開pdf在pdfviewer中打開pdf文件

我嘗試下面的代碼。它的開放pdfviewer,但與最近的文件不與我的網址?

如何在pdfviewer中直接打開文件?

Intent intent = new Intent(Intent.ACTION_VIEW, 
       Uri.parse("http://inventwithpython.com/hackingciphers.pdf")); 
     intent.setType("application/pdf"); 
     PackageManager pm = getPackageManager(); 
     List<ResolveInfo> activities = pm.queryIntentActivities(intent, 0); 
     if (activities.size() > 0) { 
      startActivity(intent); 
     } else { 
      // Do something else here. Maybe pop up a Dialog or Toast 
      Toast.makeText(getApplicationContext(),"No pdf found" , Toast.LENGTH_LONG).show(); 
      final String appName = "com.adobe.reader"; 
      try { 
       startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id="+appName))); 
      } catch (android.content.ActivityNotFoundException anfe) { 
       startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id="+appName))); 
      } 

     } 

回答

0

試試這個代碼

Uri uri = Uri.parse("http://inventwithpython.com/hackingciphers.pdf"); 

     Intent pdfOpenintent = new Intent(Intent.ACTION_VIEW,uri); 
     pdfOpenintent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
     pdfOpenintent.setDataAndType(uri, "application/pdf"); //) 

     try { 
      startActivity(pdfOpenintent); 
     } catch (ActivityNotFoundException e) { 

     } 
+0

不工作仍然 – Nick

+0

嘗試更新的代碼 – Ameer

+0

什麼更新?這是更新 – Nick