- Share URL From One Browser to Another On Android
- Let’s Get Started!
- So Which Android Browsers Support Flash?
- You’re Done!
- Android Share Intent Example for URL, Text or Image
- Android Share Intent Example Step by Step
- Step 1: Prepare XML Layout, we’ll have activity_main.xml
- Step 2: Inside the onCreate method of MainActivity.java, put the buttons and OnClickListener handlers.
- Step 3: As you’ve noticed, we have shareTextUrl() method that will be triggered every time the user clicks on the “Share Text or URL” button.
- Step 4: We also have shareImage() method for sharing images. It is triggered when the user clicks on the “Share Image” button.
- Complete MainActivity.java code:
- Today’s code output screenshots
- Sharing Content between Android apps
- Sharing text
- Sharing HTML text
- Receiving text
- Sharing files and images
- Receiving files
- The Support Library is your friend
- felquis / url-schemes.md
Share URL From One Browser to Another On Android
If you remember back when Android phones first hit store shelves, one of their big marketing draws was that they supported flash, whereas the iPhone did not. Adobe dropped support for flash on Android last year, killing this draw. While it’s still possible to view flash on an Android device, doing so can be a bit of a hassle. Flashify is an Android app that intends to help by allowing you to take a URL that won’t load flash inside one browser and share it with another. The benefit of this app is that even if you don’t have a browser installed that can run flash, it’s still the fastest way to get links from one browser to another.
Let’s Get Started!
You know the drill. The first step is to hop over to the Play Store and download the Flashify app. Got it? Good. Now, it gets trickier after this. Flashify does not open like most apps do. Instead, it hides out entirely under your share menu. To access it, you first need to load a URL inside any browser. Here I will try to load up a flash game inside of Google Chrome. As expected, I’m hit with an error message complaining about the absence of flash on my device.
Here is where Flashify comes in. All I need to do is jump over to the menu in the top right corner and select the share button.
This brings up a menu listing all of the apps that I am able to share this website with. I’m looking for Flashify.
After I’ve selected Flashify, I am prompted to select another browser to send the URL to.
Flashify will then open up the website in that browser, saving me the effort of having to copy the URL, open another browser, and paste it manually. As you can see below, the flash game I was attempting to play loads after I send it over to the default browser.
So Which Android Browsers Support Flash?
The list of browsers that support flash really have shrunken over the years. A trip over to the list of Adobe’s Certified Devices shows that the company stopped certifying devices after Android 4.0. Nevertheless, you do have a few options.
- If your phone ships with the flash plugin, chances are your default browser can play flash content. You may need to go into the settings menu for the browser and enable the flash plugin beforehand, as I had to do.
- If you’re using Firefox, Mozilla has provided instructions on their website that may get you up and running.
- You can download Photon Flash Player & Browser for free or purchase the Puffin Web Browser for $2.99. Both continue to support flash.
You’re Done!
Flashify is the fastest way to get a website from one browser to another. The app is useful for far more than just trying to open websites that use flash. Say you have a website that is otherwise not compatible with one browser but is compatible with another. What if you have a website bookmarked in one browser that you wish to save elsewhere? Flashify makes all of this far less tedious. Give it a go, and if you know of any other browsers that play flash for Android, let us know in the comments.
Источник
Android Share Intent Example for URL, Text or Image
Today I’m going to give you an android share intent example that you can use to enable your app to share contents such as URL or text and Image to other apps installed in your Android device like Facebook, Twitter, Messaging, Instagram, Evernote, etc.. Example uses of this code include:
You are building an app that browses a certain website or URL.
Your app generates an image that a user can share.
Android Share Intent Example Step by Step
Step 1: Prepare XML Layout, we’ll have activity_main.xml
Step 2: Inside the onCreate method of MainActivity.java, put the buttons and OnClickListener handlers.
Step 3: As you’ve noticed, we have shareTextUrl() method that will be triggered every time the user clicks on the “Share Text or URL” button.
Step 4: We also have shareImage() method for sharing images. It is triggered when the user clicks on the “Share Image” button.
Complete MainActivity.java code:
Please note that when you use the setType() method, you are enabling Android to filter what apps can share your content. For example, you are sharing a text or URL, the appropriate apps to be shown can be Facebook, Messaging or Email. If you are sharing an image, proper apps can be Instagram, Snapseed or Picasa.
Today’s code output screenshots
Share Text or URL button was touched. Take note of the apps on the list.
User chose to share to Facebook
“Share Image” button was touched. Apps was different on the list.
User chose to share with Gmail. Our image was attached.
User chose to share to Snapseed.
If you have any suggestions to improve this post, please drop it in the comments section below! I’ll be glad to update this post for further improvement. Thanks for reading our Android Share Intent Example!
Источник
Sharing Content between Android apps
Sharing is caring, as they say, but sharing on Android means something perhaps slightly different. ‘Sharing’ is really shorthand for sending content such as text, formatted text, files, or images between apps.
So if ‘sharing’ == sending content, it makes slightly more sense that it is implemented using ACTION_SEND (or ACTION_SEND_MULTIPLE) Intents and its dozen extras.
While that approach is perfectly valid, I prefer to use ShareCompat, a set of classes in the v4 Support Library designed to make it easy to build intents for sharing content.
Sharing text
Sharing plain text is, as you might imagine, a good place to start. In fact, there’s not a whole lot to it:
ShareCompat.IntentBuilder uses a fluent API where you can chain together multiple method calls, using only the ones you need. For sharing, one of the most important parts is picking the right mime type — this is how apps filter what type of content they can receive. By using text/plain, we signify that our Intent will only contain plain text. Then, of course, setText() is how we actually add the CharSequence to the Intent to send. And while you can certainly send styled text using setText(), there’s no guarantee that the receiving app will honor that styling, so you should ensure that the text is legible with or without styling.
You’ll note we then use resolveActivity() before calling startActivity(). As mentioned in Protecting Implicit Intents with Runtime Checks, this is critical to prevent an ActivityNotFoundException when there is no Activity available to handle the mime type you have selected. While probably not as much of a concern with text/plain, it may be much more common with other types.
Note: when you use startActivity(shareIntent), that respects any default apps the user has set (i.e., if they’ve previously selected sharing all “text/plain” items to a certain app). If you’d like to instead always show a disambiguation chooser, use the intent generated from IntentBuilder.createChooserIntent() as explained in the ACTION_CHOOSER documentation.
Sharing HTML text
Some apps, most notably email clients, also support formatting with HTML. The changes, compared to plain text, are fairly minor:
The differences here are that we use of setHtmlText() in place of setText() and a mime type of text/html replacing text/plain. Here ShareCompat actually does a little bit extra: setHtmlText() also uses Html.fromHtml() to create a fallback formatted text to pass along to the receiving app if you haven’t previously called setText() yourself.
Given that many of the apps that can receive HTML text are email clients, there’s a number of helper methods to set the subject, to:, cc:, and bcc: email addresses as well — consider adding at least a subject to any share intent for best compatibility with email apps.
Of course, you’ll still want to call resolveActivity() just as before — nothing changes there.
Receiving text
While the focus so far has been on the sending side, it is helpful to know exactly what is happening on the other side (if not just to build a simple receiving app to install on your emulator for testing purposes). Receiving Activities add an intent filter to the Activity:
The action is obviously the more critical part — without that there’s nothing that would denote this as an ACTION_SEND (the action behind sharing). The mime type, same as with our sending code, is also present here. What isn’t as obvious are the two categories. From the element documentation:
Note: In order to receive implicit intents, you must include the CATEGORY_DEFAULT category in the intent filter. The methods startActivity() and startActivityForResult() treat all intents as if they declared the CATEGORY_DEFAULT category. If you do not declare it in your intent filter, no implicit intents will resolve to your activity.
So CATEGORY_DEFAULT is required for our use case. Then, CATEGORY_BROWSABLE allows web pages to natively share into apps without any extra effort required on the receiving side.
And to actually extract the information from the Intent, the useful ShareCompat.IntentReader can be used:
Similar to IntentBuilder, IntentReader is just a simple wrapper that make it easy to extract information.
Sharing files and images
While sending and receiving text is straightforward enough (create text, include it in Intent), sending files (and particularly images — the most common type by far) has an additional wrinkle: file permissions.
The simplest code you might try might look like
And that almost works — the tricky part is in getting a Uri to the File that other apps can actually read, particularly when it comes to Android 6.0 Marshmallow devices and runtime permissions (which include the now dangerous READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permissions).
My plea: don’t use Uri.fromFile(). It forces receiving apps to have the READ_EXTERNAL_STORAGE permission, won’t work at all if you are trying to share across users, and prior to KitKat, would require your app to have WRITE_EXTERNAL_STORAGE. And really important share targets, like Gmail, won’t have the READ_EXTERNAL_STORAGE permission — so it’ll just fail.
Instead, you can use URI permissions to grant other apps access to specific Uris. While URI permissions don’t work on file:// URIs as is generated by Uri.fromFile(), they do work on Uris associated with Content Providers. Rather than implement your own just for this, you can and should use FileProvider as explained in the File Sharing Training.
Once you have it set up, our code becomes:
Using FileProvider.getUriForFile(), you’ll get a Uri actually suitable for sending to another app — they’ll be able to read it without any storage permissions — instead, you are specifically granting them read permission with FLAG_GRANT_READ_URI_PERMISSION.
Note: we don’t call setType() anywhere when building our ShareCompat (even though in the video I did set it). As explained in the setDataAndType() Javadoc, the type is automatically inferred from the data URI using getContentResolver().getType(uriToImage). Since FileProvider returns the correct mime type automatically, we don’t need to manually specify a mime type at all.
If you’re interested in learning more about avoiding the storage permission, consider watching my Forget the Storage Permission talk or at least go through the slides, which covers this topic in depth at 14:55 (slide 11).
Receiving files
Receiving files isn’t too different from text because you’re still going to use ShareCompat.IntentReader. For example, to make a Bitmap out of an incoming file, it would look like:
Of course, you’re free to do whatever you want with the InputStream — watch out for images that are so large you hit an OutOfMemoryException. All of the things you know about loading Bitmaps still apply.
The Support Library is your friend
With both ShareCompat (and its IntentBuilder and IntentReader) and FileProvider in the v4 Support Library, you’ll be able to include sharing text, HTML text, and files in your app with the best practices by default.
Источник
felquis / url-schemes.md
Assume the user is on iOS Safari, but you want it to open an URL on Chrome, Firefox or Opera. How do you do that?
To open on Chrome
check out Chrome iOS Docs for more information
To open on Firefox
Check out Firefox Docs for more information
To open on Opera
Check out this page for more information, I couldn’t found official Opera Documentation
Assume the users is on a in-app webview or any other browser, but an API is not support in-app browser, so you need to link the user to Safari, how do you achieve that?
I couln’t find a URL Scheme for Safari, so I need to link like safari://url so whenever the user clicks on it, it will be handled by Safari.
I tried x-web-search but it didn’t work
Demo and resources
Codepen Demo, Inter App Communication, Apple URL Schemes, I think registerProtocolHandler is somewhat related.. I think this bug is also somewhat related, cause there’s developers trying to figure out if a URL Scheme is available in the platform, check out this Stackoverflow question
Should we work on a standard way to share information between web apps to installed application and installed application to web apps and web apps to web apps, on desktop, tablets and smartphone?
There’s basic necessities when developing a rich web app.
What are the apps the user can share this piece of information?
Whatsapp has the whatsapp:// URL Scheme, but there’s no way to check if the given URL Scheme is available in the platform
If the user clicks in share, the browser/platform should give a list of applications/web apps the user can share the given information, it could be a URL, String, File Buffer would be great, for example.. The user apply a custom filter to an image on a web app. So the user wants to share it on Instagram.
Is a specfic URL Scheme available?
There’s no standard way to check if a URL Scheme is available
How can I offer my web app the oportunite to the user share the information?
Android has a popup where the user choose where he wants to share the information, a URL or String.. or a image base64 enconded.. So. If my web site provide a way to share images, strings and links.. How can I tell the device/browser my web app can share this kind of information?
I found out the best reading these days is this blog post about a failed Web API called Web Indents, follow all the links
Thank you for reading, I appreciate your help.
Источник