View PDF from link without saving/downloading in Android
If you follow this guide i think you can reach your achievement
https://blog.mindorks.com/how-to-open-a-pdf-file-in-android-programmatically
Open PDF in Android without it Automatically Being Downloaded To Device
Depends on what you mean by downloaded. Whenever you view ANYTHING on the web, you have to download it. Downloading is the process of receiving data from a remote source. You have to download any webpage or url to view it.
It seems what you're asking is "Does it have to be saved to a file in the Downloads folder". In which case no, it doesn't. You could download it and keep it in RAM.
How to open pdf files in webview in pdfactivity?
BINGO!! My issue resolved can open pdf directly using BufferedInputStream
I created two activity, First Activity to load all pdfs in webview. When user clicks the link of pdf, the pdfurl
fetches the url as strings, passes strings to next activity.
PdfActivity.java
final String pdfurl = view.getHitTestResult().getExtra();
Intent intent = new Intent(PdfActivity.this,PdfViewer.class);
intent.putExtra("PDFURL",pdfurl);
startActivity(intent);
Second Activity is PdfViewer, bateksc pdfviewer to load pdf from url, edited as above
PdfViewer.java
package ak.wp.meto.activity;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.KeyEvent;
import android.widget.TextView;
import android.widget.Toast;
import com.github.barteksc.pdfviewer.PDFView;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import ak.wp.meto.R;
public class PdfViewer extends Activity {
private TextView txt; // You can remove if you don't want this
private PDFView pdf;
String value = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_custom_pdf);
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
value = bundle.getString("PDFURL");
}
System.out.println("PRINT PDFVIEWER DATA" +value);
pdf = (PDFView) findViewById(R.id.pdfView); //github.barteksc
txt = findViewById(R.id.txtPdf);
String pdfUrl = value;
try{
new RetrievePdfStream().execute(pdfUrl);
}
catch (Exception e){
Toast.makeText(this, "Failed to load Url :" + e.toString(), Toast.LENGTH_SHORT).show();
}
}
class RetrievePdfStream extends AsyncTask<String, Void, InputStream> {
@Override
protected InputStream doInBackground(String... strings) {
InputStream inputStream = null;
try {
URL url = new URL(strings[0]);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
if (urlConnection.getResponseCode() == 200) {
inputStream = new BufferedInputStream(urlConnection.getInputStream());
}
} catch (IOException e) {
return null;
}
return inputStream;
}
@Override
protected void onPostExecute(InputStream inputStream) {
pdf.fromStream(inputStream).load();
}
}
}
Related Topics
How to Get Imsi Number in Android Using Command Line
Error With Android Studio: Cannot Launch Avd in Emulator
Http Failure Response for (Unknown Url): 0 Unknown Error on Android
Android Emulator Is Start But Window Show Blank Screen
Detect or Prevent If User Uses Fake Location
How to Set Space Between Listview Items in Android
React Native | Failed to Install the App. Please Accept All Necessary Sdk Licenses Using Sdk Manager
Remove Apk from Library in Google Play Developer Console
Android: How to Open a Specific Folder Via Intent and Show Its Content in a File Browser
How to Set Up Android Studio to Work Completely Offline
How to Access /Storage/Emulated/0/
How to Access Data/Data Folder in Android Device
How to Format Credit Card Expiry Date in Mm/Yy When Entered by User
How to Unlock Android Phone Through Adb
How to Place an Imageview on Top of Another Imageview in Android
How to Remove Android Auto-Suggest Underlining in Edittext