How to use web app to share content in mobile? - android

I couldn't find anything on this. I read everything about protocol/content handlers but didn't seem to solve my problem at all.
I'm trying to find a way to allow an Android user (for example) to share content using a web application.
Examples:
1) Viewing a Youtube video in the native app. User selects 'share' and a bunch of icons appear. I want my web app to be there, so when user selects its icon, a URL is opened in the browser with a magic parameter passing the video URL so I can handle that.
2) Well, you get the idea now :)
Any ideas?
Thanks.

If your app can do some task and you want that message to be conveyed to all other apps, Android way of doing this is - Intent Filters (It tells the world what the app can do)
Intent - Android way of telling - Hey i want to get this job done ?
If you build a social app that can share messages or photos with the user's friends, your app should support the ACTION_SEND intent. so users can initiate a "share" action from another app and launch your app to perform the action.
To allow other apps to start your activity, you need to add an element in your manifest file for the corresponding element.
If your activity handles both text and images for both the ACTION_SEND and ACTION_SENDTO intents. In this case, you must define two separate intent filters for the two actions because a ACTION_SENDTO intent must use the data Uri to specify the recipient's address using the send or sendto URI scheme. For example:
<activity android:name="ShareActivity">
<!-- filter for sending text; accepts SENDTO action with sms URI schemes -->
<intent-filter>
<action android:name="android.intent.action.SENDTO"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="sms" />
<data android:scheme="smsto" />
</intent-filter>
<!-- filter for sending text or images; accepts SEND action and text or image data -->
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="image/*"/>
<data android:mimeType="text/plain"/>
</intent-filter>
</activity>
This link has all the above mentioned details with lot more information.
http://developer.android.com/training/basics/intents/filters.html

Related

How does twitter/facebook know on which apps tweet/status/images can be shared?

My question is when I want to share a tweet on from twitter app when I press the share button a pop up opens and displays all the apps that on which I can share my tweet. How does twitter app knows which apps to display?
This is similar to when an image is opened a pop up comes up and asks for the app we want to view the image in. How does any OS figures out which apps to display.
My guess is that something has to be done with the original application itself.
Attached is an image for reference
In the above screenshot Facebook, Twitter, G+ etc are using Intent Filters.
By defining intent filter you can achieve this. You can register your Android components via intent filters for certain events.If a component does not define one, it can only be called by explicit intents. The key for this registration is that your component registers for the correct action, mime-type and specifies the correct meta-data.
Eg.
<activity android:name=".BrowserActivitiy"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http"/>
</intent-filter>
</activity>
Above code will register an Activity for the Intent which is triggered when someone wants to open a webpage.
Source: http://www.vogella.com/tutorials/AndroidIntent/article.html

How to use only my app for intent-filter URL with specific prefix?

Suppose we have an activity to resolve external URL links with a specifix pathPrefix. It's not a problem. The problem is to have a method to make those links is only resolvable with my app.
For example:
We have this intent filter
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="example.com"
android:pathPrefix="/specific_prefix/"
android:scheme="http" />
</intent-filter>
And I want only my app to be used for example for "example.com/specific_prefix/etc". If that eve possible?
And I want only my app to be used for example for "example.com/specific_prefix/etc". If that eve possible?
No.
First, how URLs are interpreted is up to the app interpreting the URLs. Some Web browsers, when they encounter an http URL, will always handle it themselves, rather than seeing if a third-party app has advertised support for it.
Second, in cases where there are two or more apps that claim to support a certain operation, the user chooses which one to use. In your case, Web browsers and your app will claim to handle that URL, and the user can choose whichever of those that the user wants.
With Android 6.0's app links, you can avoid the chooser by default, so if a chooser would have appeared, the user will be taken straight to your app. The user can disable this in Settings, though.

Possible to bypass Android Intent Filter?

In my app I have an intent filter set to match certain types of links if clicked in a web browser or other field. It currently looks like this:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="www.mydomain.com"
android:scheme="http" />
<data
android:host="mydomain.com"
android:scheme="http" />
<data
android:host="m.mydomain.com"
android:scheme="http" />
</intent-filter>
This works well. If you click a link say http://www.mydomain.com/article_name then the user gets the option of opening the article in the app and I can show the content uniquely. Here's the question - in the app I want to provide an option for the user to still break out and "Open in Browser". Yet if I do this and just try to fire off an intent to launch the browser, my app catches the link again and we go around in a circle.
How can I specifically force a link to be opened in the browser?
I believe you can use the answers provided in this thread to achieve your end. Basically, when you go to launch the "open in browser" intent, you can preview the activities that will be able to open it. From there, you can select one that isn't your app and set that as the package on the intent, which will cause the other app to open it.
At worst, you could force the creation of the chooser which would contain both your app and the other apps that can open your site, enabling the user to pick the browser.
This other question might also be useful, as its answers contain an implementation of a custom chooser which apparently allows you to filter the visible activities, so you could remove your app.
I don't know any way to bypass Android Intent Filter.
If user uses Android default Browser or Chrome, you should use the way in following link to open an Intent specifically.
https://developers.google.com/chrome/mobile/docs/intents

Launcing Applications with Custom URI on Android

I am developing an application on Android and my application needs to be launched whenever a URI like (myscheme://mydata) is clicked on an SMS or Email.
I am using following filter for my app :
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="secture"/>
</intent-filter>
However on emails and SMS messages, my URIs with the form of myscheme://mydata show up as
regular tests and i cannot click on them to launch my application.
Thanks for help
Edit :
I found out that Linkfy class does something similar however it modifies your own text into links. What I need is modifying other applications such as Email and SMS. So is it possible to change another applications Linkfy?
So is it possible to change another applications Linkfy?
No, sorry.
Instead of myscheme://mydata, use http://mydomain/mypath. You can create an <intent-filter> for this so that you get control instead of the browser, and the resulting URLs will be friendlier to other apps. As a bonus, you can put a real Web page at that URL, so if somebody who does not have your app winds up with your URL (e.g., forwarded email), the URL will still work..

How to add app to "Share via" list for camera picture on Android

I am building an app that starts when a user takes a picture using their build-in Android camera, then taps the Share button, then chooses my app as the sharer, which is expecting an incoming path to the picture that was just taken, which it uses for processing.
Question: how do I add an option to the "Share via" list that points to my app? Right now there are options like Facebook, Email, Messages, Twitter, Picasa, and I want to add my app w/ an icon.
I'm stuck! And, Google'ing for this is not easy, as "android add to share via list camera" yields a lot of results. I'm building the app with AppInventor (AI), but, AI does not allow developers to edit the Share via list, so maybe this will have to be a separate mini app that just adds to the list...? Hopefully not, because it'd be great to have just 1 app for users to download/install.
Functions like the "share via" in Android work with broadcast intents. The app creates this intent and the system reports all the activities that can execute that (twitter, fb...) You specify what an activity can do by means of intent filters.
In your case I searched for "android camera share intent" and found generally that the intent filter looks like this:
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
(not sure about the data section)
I don't know if camera app uses a specific content provider, anyway your app should be able to manage at least the URI scheme that app uses.
I wanted to Share text content and i add the below code in manifest and its works...
<activity android:name=".SendMessage.SendMessageLeads"
android:label="SMS Composer"
android:icon="#drawable/sms_composer">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>

Categories

Resources