2012-10-15 16 views
7

क्या किसी को भी एंड्रॉइड में पीडीएफ फाइल को खोलने का विचार है?संपत्ति फ़ोल्डर से एंड्रॉइड में पीडीएफ फाइल कैसे खोलें?

public class SampleActivity extends Activity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     CopyReadAssets();  
    } 

    private void CopyReadAssets() { 
     AssetManager assetManager = getAssets(); 

     InputStream in = null; 
     OutputStream out = null; 
     File file = new File(getFilesDir(), "git.pdf"); 
     try { 
      in = assetManager.open("git.pdf"); 
      out = openFileOutput(file.getName(), Context.MODE_WORLD_READABLE); 

      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://" + getFilesDir() + "/git.pdf"), 
       "application/pdf"); 

     startActivity(intent); 
    } 

    private void copyFile(InputStream in, OutputStream out) throws IOException { 
     byte[] buffer = new byte[1024]; 
     int read; 
     while ((read = in.read(buffer)) != -1) { 
      out.write(buffer, 0, read); 
     } 
    } 
} 
+0

आप इस लिंक पर देख सकते हैं: मेरे कोड इस इस लग रहा है http://stackoverflow.com/questions/6491210/how-to-open-a-pdf-stored-either-in-res-raw-or-assets-folder – omi0301

+0

की जाँच इस http: // stackoverflow.com/questions/6491210/how-to-open-a-pdf-stored-either-in-res-raw-or-assets- फ़ोल्डर – Aamirkhan

+0

@sai कृपया निर्दिष्ट करें कि आप किस समस्या का सामना कर रहे हैं, यानी कोई अपवाद/त्रुटि, या उपलब्ध पीडीएफ दर्शक सूची की ऐप प्रदर्शित सूची? –

उत्तर

2

यहाँ परिसंपत्ति फ़ोल्डर से pdf फ़ाइल को खोलने के लिए कोड है, लेकिन आप पीडीएफ रीडर आपके उपकरण पर स्थापित किया जाना चाहिए:

private void CopyAssets() { 

     AssetManager assetManager = getAssets(); 

     InputStream in = null; 
     OutputStream out = null; 
     File file = new File(getFilesDir(), "fileName.pdf"); 
     try { 
      in = assetManager.open("fileName.pdf"); 
      out = openFileOutput(file.getName(), Context.MODE_WORLD_READABLE); 

      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://" + getFilesDir() + "/fileName.pdf"), 
       "application/pdf"); 

     startActivity(intent); 
    } 

    private void copyFile(InputStream in, OutputStream out) throws IOException { 
     byte[] buffer = new byte[1024]; 
     int read; 
     while ((read = in.read(buffer)) != -1) { 
      out.write(buffer, 0, read); 
     } 
    } 
+3

यह उत्तर अनिवार्य रूप से इस से क्रियापद प्रतिलिपि बनाई गई है: http://stackoverflow.com/questions/17085574/पढ़-ए-पीडीएफ-फ़ाइल-से-संपत्ति-फ़ोल्डर – csvan

संबंधित मुद्दे