2014-01-15 56 views
-1

如何在我的應用程序中使用pdf閱讀器的現有代碼實現pdf閱讀器。請儘快幫助我!在Android應用程序中調用pdf閱讀器

我們需要從本地目錄(Sdcard)將PDF閱讀器嵌入到我們定製的Android應用程序之一中。

+0

你介意分享一下你迄今爲止試過的東西嗎? –

+0

搜索SO使用關鍵字「[android]啓動pdf閱讀器」...這個問題已經被回答了很多次 – CSmith

+0

http://stackoverflow.com/questions/2916108/android-open-a-pdf-from-my-app -using-built-in-pdf-viewer,http://stackoverflow.com/questions/5143280/pdf-reading-on-android –

回答

0

按照我用來在我的android應用程序中顯示PDF文檔的PdfUtils類。

import java.io.File; 
import java.util.List; 

import android.content.ActivityNotFoundException; 
import android.content.Context; 
import android.content.Intent; 
import android.content.pm.PackageManager; 
import android.content.pm.ResolveInfo; 
import android.net.Uri; 
import android.os.Environment; 

public class PdfUtils { 

    static public boolean isAnyPdfReaderAvailable(Context context) { 
     Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("path-to-document")); 
     intent.setType("application/pdf"); 
     PackageManager pm = context.getPackageManager(); 
     List<ResolveInfo> activities = pm.queryIntentActivities(intent, 0); 
     if (activities.size() > 0) 
      return true; 
     else 
      return false; 
    } 

    static public void loadPdfInReader(Context context, String doc) throws ActivityNotFoundException, Exception { 
     try { 
      Intent intent = new Intent(); 
      intent.setPackage("com.adobe.reader"); 
      File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + doc); 
      intent.setDataAndType(Uri.fromFile(file), "application/pdf"); 
      context.startActivity(intent); 
     } catch (ActivityNotFoundException activityNotFoundException) { 
      activityNotFoundException.printStackTrace(); 
      throw activityNotFoundException; 
     } catch (Exception otherException) { 
      otherException.printStackTrace(); 
      throw otherException; 
     } 
    } 

} 
相關問題