Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As Barak said you can copy it out of assets to internal storage or the SD card and open it from there using inbuilt pdf applications.</p> <p>Following Snippet will help you. (I have updated this code to write to and read files from internal storage.</p> <p>But i dont recommend this approach because pdf file can be more than 100mb in size.</p> <p>So its not recommended to save that huge file into internal storage</p> <p>Also make sure while saving file to internal storage you use </p> <pre><code>openFileOutput(file.getName(), Context.MODE_WORLD_READABLE); </code></pre> <p>Then only other applications can read it.</p> <p>Check following snippet.</p> <pre><code>package org.sample; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.content.res.AssetManager; import android.net.Uri; import android.os.Bundle; import android.util.Log; 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); } } } </code></pre> <p>Make sure to include</p> <p><code>&lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;</code> </p> <p>in manifest</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload