Unable to open online streaming PDF in browser - android

How to open a online stream assets in android.
I had used Intent, but the file gets downloaded and not getting opened in browser.
var uri = Android.Net.Uri.Parse(Url);
Intent intent = new Intent(Intent.ActionView, uri);
StartActivity(intent);
Don't want to use Web view. Any help ?

How to open a online stream assets in android.
You could using google doc service to achieve this function, it just need you
to modify your Url like this :
string Url = "https://docs.google.com/gview?embedded=true&url=" + strPdf;
//Eg :string Url = "https://docs.google.com/gview?embedded=true&url=" + "https://www.adobe.com/devnet/acrobat/pdfs/pdf_open_parameters.pdf";
var uri = Android.Net.Uri.Parse(Url);

Related

Android.Net.Uri change caching time

How can I change caching time? I receive a notification when the PDF file is updated on the server. I get the same link, but with another (previous) document. Since URL hashes the previous document, it opens the old one, not the updated one.
Android.Net.Uri uri = Android.Net.Uri.Parse(url);
Intent browserIntent = new Intent(Intent.ActionView, uri);
try {
context.StartActivity(browserIntent);
}
catch (ActivityNotFoundException e) {
Console.WriteLine(e);
Toast.MakeText(context, "Install PDF reader", ToastLength.Short);
}
My URL doesn't change, however, pdf file changes.
I solved my problem, I just changed the URL. And now every URL to the pdf file is unique and not cached.
url = url.Replace(" ", "%20");
url = $"{url}?random_number={new Date().Time}";

How to open pdf file in external app or in webview size is greater than 25mb

hello i want to show pdf file in webview or in external app.
1) i use this url
https://docs.google.com/gview?embedded=true&url= +pdfurl , but google says "Whoops There was a problen while previewing document"
2) if i use intent to open the url in external app then they didnot load the file in external app.
3) if i use the intent to open the url in browser then its start downloading the pdf file.
Intent ii=new Intent(Intent.ACTION_VIEW);
ii.setDataAndType(Uri.parse(pdf),"text/html");
try {
startActivity(ii);
}catch (ActivityNotFoundException e)
{
Toast.makeText(QuranPara.this, "NO Pdf Viewer", Toast.LENGTH_SHORT).show();
}
here is the complete url https://docs.google.com/gview?embedded=true&url=www.elibrary.alnoorpk.com/PDF%20Books/Lafzi_aur_bamahawrah_terjma_2015/Para%201%20(Lafzi%20aur%20Bamuhawra%20Tarjma).pdf
check the image
To show it in WebView try something like this
String pdf = "http://www.adobe.com/devnet/acrobat/pdfs/pdf_open_parameters.pdf";
webview.loadUrl("http://drive.google.com/viewerng/viewer?embedded=true&url=" + pdf);
To show it in browser try something like this
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(pdf_url));
startActivity(browserIntent);
If your files are in assets first copy them to the external storage. Hope that you have handled permission flow.
Try the following code for offline
File pdfFile = new File(Environment.getExternalStorageDirectory(),"pdfName.pdf");//Pdf file path
if (pdfFile.exists()) //Checking for the file is exist or not
{
Uri path = Uri.fromFile(pdfFile);
Intent objIntent = new Intent(Intent.ACTION_VIEW);
objIntent.setDataAndType(path, "application/pdf");
objIntent.setFlags(Intent. FLAG_ACTIVITY_CLEAR_TOP);
startActivity(objIntent);//Staring the pdf viewer
} else {
Toast.makeText(getActivity(), "The file not exists! ", Toast.LENGTH_SHORT).show();
}
Try the following for the webview option if you choose that
WebView webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
String pdf = "online pdf link";
webview.loadUrl("http://drive.google.com/viewerng/viewer?embedded=true&url=" + pdf);
But Remember if you use google docs for viewing the pdf or any other doc, google docs may throw you the error stating
You've reached the bandwidth limit for viewing or downloading files that aren't in Google Docs format..... So doesn't seem reliable
So, be cautious with google doc viewing

Image url start with https not downloading android

I'm downloading image using url like below,
final String url = article.image.url;
String parentFolder = ""+article.category_id;
final String fileName = ""+article.image.id;
FileManager fileManager = BDevice.getFileManager(mContext);
final File file = BDevice.getFileManager(mContext).getFile(""+article.category_id, parentFolder, fileName);
Uri uri = null;
if (fileManager.isFileExists(file.getAbsolutePath())) {
uri = Uri.fromFile(file);
} else {
if (url != null) {
uri = Uri.parse(url);
}
}
holder.image.setImageURI(uri);
But this is working for this url "https://citylanedev.blob.core.windows.net/citylane/2016/10/Pharmacie_Icon.png"
and not working for this url "https://dev.citylaneapp.com/wp-content/uploads/2016/09/france-mont-saint-michel-2.jpg". After remove 's' from the second url like "http://dev.citylaneapp.com/wp-content/uploads/2016/09/france-mont-saint-michel-2.jpg" its working fine. But i dnt want to remove 's' from the url. I want to download image from the second url. So could you please suggest me any idea to do this?
when I try to open the urls in the browser, the second one
gives that warning, mostly it's a server issue that the server claims it's secured but probably it's SSL Certificates aren't installed, you should contact the server admin.

When using a URL that links to an MP3 stream, how do I convert it to a URI?

I'm making an app that uses MediaPlayer to play internet radio streams.
Research online tells me that it's easiest to use a URI.
I was wondering how I convert this link to a URI?
The tutorial I found was a little confusing on this point: http://teamrock.planetwideradio.com:8000/teamrockhigh
Use the toURI method, which
Returns the URI equivalent to this URL.
In your case:
URL url = new URL("http://teamrock.planetwideradio.com:8000/teamrockhigh");
URI uri = url.toURI();
It depends if you are using the link as an URL or maybe just a string. If you just look for a way to convert an URL to an URI then the code is rahter short:
// Convert a URL to a URI
URI uri = null;
URL url = null;
try{
url = new URL("http://teamrock.planetwideradio.com:8000/teamrockhigh");
uri = url.toURI();
}
catch (URISyntaxException e) {
// Exception handling
}
You can also use the string directly to create an URI object:
URI uri = new URI("http://teamrock.planetwideradio.com:8000/teamrockhigh");

upload kml map to my android app

i tried to find how i could load kml file and I found that I can use:
Intent mapIntent = new Intent(Intent.ACTION_VIEW);
Uri uri1 = Uri.parse("geo:0,0?q=http://code.google.com/apis/kml/
documentation/KML_Samples.kml");
mapIntent.setData(uri1);
startActivity(Intent.createChooser(mapIntent, "Sample"));
is there any other way such that i can upload the kml file locally from my pc rather than having to upload it to a website, then use it..as I am developing an applications and usually other users wont be able to access the kml of they dont have the username and password for the link
please if anyone can help, I would be thankful.
You can create an account in googlecode and upload the kml file, so it'll be on the internet and everybody can see it
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Uri uri = Uri.parse("geo:0,0?q=http://miruta.googlecode.com/files/miruta.kml");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, uri);
mapIntent.setData(uri);
startActivity(Intent.createChooser(mapIntent, "Sample Map"));
}
KML map in android is now officially available on this link.
You can easily load KML file from local resource folder or from inputstreams into your android app as below.
From local resource:-
KmlLayer layer = new KmlLayer(map, R.raw.geojson_file, context);
From InputStreams:-
InputStream inputStream = // InputStream containing KML data
KmlLayer layer = new KmlLayer(map, inputStream, context);

Categories

Resources