Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First Create a downloader class </p> <pre><code>public class Downloader { public static void DownloadFile(String fileURL, File directory) { try { FileOutputStream f = new FileOutputStream(directory); URL u = new URL(fileURL); HttpURLConnection c = (HttpURLConnection) u.openConnection(); c.setRequestMethod("GET"); c.setDoOutput(true); c.connect(); InputStream in = c.getInputStream(); byte[] buffer = new byte[1024]; int len1 = 0; while ((len1 = in.read(buffer)) &gt; 0) { f.write(buffer, 0, len1); } f.close(); } catch (Exception e) { e.printStackTrace(); } } } </code></pre> <p>After that create an activity which downloads the PDF file from internet, </p> <pre><code>public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); String extStorageDirectory = Environment.getExternalStorageDirectory() .toString(); File folder = new File(extStorageDirectory, "pdf"); folder.mkdir(); File file = new File(folder, "Read.pdf"); try { file.createNewFile(); } catch (IOException e1) { e1.printStackTrace(); } Downloader.DownloadFile("http://122.248.233.68/pvfiles/Guide-2.pdf", file); showPdf(); } public void showPdf() { File file = new File(Environment.getExternalStorageDirectory()+"/Mypdf/Read.pdf"); PackageManager packageManager = getPackageManager(); Intent testIntent = new Intent(Intent.ACTION_VIEW); testIntent.setType("application/pdf"); List list = packageManager.queryIntentActivities(testIntent, PackageManager.MATCH_DEFAULT_ONLY); Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); Uri uri = Uri.fromFile(file); intent.setDataAndType(uri, "application/pdf"); startActivity(intent); } } </code></pre> <p>Finally at last declare persmissions in <code>AndroidManifest.xml</code></p> <pre><code>&lt;uses-permission android:name="android.permission.INTERNET"&gt;&lt;/uses-permission&gt; &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

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