When I open the Android's default browser I want to add a button or a menu entry when it's clicked to open my Intent and pass me the current url parameter.
Is this possible in Android?
Only by means of the Share option, if the browser in question has one. The standard AOSP Browser app will have such a "Share" option in the action overflow. It triggers an ACTION_SEND Intent, with a MIME type of text/plain, so any activities claiming to support that in the manifest via an <intent-filter> will be able to respond:
<intent-filter android:label="#string/app_name">
<action android:name="android.intent.action.SEND"/>
<data android:mimeType="text/plain"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
Of course, you can get the current url:
URL url = new URL(mWebView.getUrl());
I don't know if I understood this right, but I think this what you want.
When the user clicks your button, you can redirect to a custom url, somesite://current_page_url. using javascript or the addon's capability.
That can be picked up by your intent filter with host set to "somesite", as done here.
Related
What needs to be done to make your app appear as an option app.
For eg, when I select an image file, android shows me a list of applications to open the file with, like Gallery,Photos etc.
I want that android also shows my app in this list.
How to achieve this? I am unable to understand which android classes to use for it? Or do I need to modify manifest file to add some specific intents?
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
I want to broadcast my custom intent when i click a link of my html page from browser. I know android system will broadcast "android.intent.action.VIEW" for this and i can receive this in my application but doing this will list my application for every clickable link so i want to broadcast my custom intent action.
I want to broadcast my custom intent when i click a link of my html
page from browser.
You can do that in two ways, the exact choice depend on your use case.
Create an <intent-filter> to open selected links (links of your website)
Change your link on the website to <a href="intent://...>
The first method gives you flexibility to leave the links on your website as it is and it will also helps in deeplinking and AppIndex. Where as the second method will make you change all the links in the website.
I know android system will broadcast "android.intent.action.VIEW" for
this and i can receive this in my application but doing this will list
my application for every clickable link so i want to broadcast my
custom intent action.
It will not list your application for every clickable link on the web, it will only open your app for your website links. If you don't want to do that and only open app for one specific link of your website, you should use method 2 above.
Just a note for the second mehtod
Make sure to implement a fallback url, as suggested by Google
When an intent could not be resolved, or an external application could
not be launched, then the user will be redirected to the fallback URL
if it was given.
The link should look like this
<a href="intent://scan/#Intent;scheme=zxing;package=com.google.zxing.client.android;S.browser_fallback_url=http%3A%2F%2Fzxing.org;end">
Notice the S.browser_fallback_url for fallback
I have solved this by following
create test.html file with this single line
Open Your Application Directly
Here "example.com/test?id=12345" can be any thing you want this will be passed as intent data in our in our onCreate() method so i have given id for example.
"scheme" can be any string we need to write same scheme in our menifest.xml for intent-filter
"package" is your app package name to differentiate it from other app with same scheme
Note : If app is not installed in device then it will open google playstore from given valid package name
in AndroidMenifest.xml file
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</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:scheme="myapp" />
</intent-filter>
you can add intent filter for any activity i have given to launcher activity
note the <data android:scheme="myapp" /> scheme name must be same as given in HTML file before.
Done! open html file in any browser of your device & click on link it will directly open your app.
You can get intent data in your activity's onCreate() method like
Intent intent = getIntent();
if (intent != null && intent.getData() != null) {
Uri data = intent.getData();
String path = data.getPath();
String id = data.getQueryParameter("id");
Log.d("ID", ": " + id);
}
I am trying to implement a new feature for my android application.
scenario :
when some event occurs, the camera sends an email to my (Gmail) account.
on opening the mail, it will have a link (html).
when user clicks on that link, it should launch my application Home activity.
I need to understand :
how to create that html link.
how can i make the link to launch my application Home activity.
kindly help me to understand what all things i need to do in my application.
I used "Blackbelt's" user comment and i was able to get the intent html link working.
But my problem is : i want to use a custom scheme "mobile" instead of "http"
I am using Gmail to use the link. But when i send using custom scheme. Gmail doesnt recogonise as hyperlink. So i cannot click on the link.
Please help me how to use a custom scheme. with gmail
you need to register an intent-filter for your Activity on the AndroidManifest.xml file, defining a custom url. . E.g.
<activity android:name="path.to.YourActivity" >
<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="https"
android:host="it.is.my.app" />
</intent-filter>
</activity>
So if you press on a link like https://it.is.my.app, you should be prompted with the android intent chooser, with your app
And if possible, how can I get this behavior for 'my' app?
For example, when a user navigates to the URL 'example.com/*' (any page starting with example.com), I'd want it so the 'complete this action with' menu shows up listing all of the browsers and this particular app?
I've done some reading of the Intent documentation, but it seems like you can only create them for phone data, not web URLs.
Edit: anyone? I've looked into this some more, but haven't had any luck. I'd like to set a bounty, but I don't have that option yet. If it isn't possible, I guess I'll just make a way to paste in a URL.
It's pretty simple, actually! What you want is an intent filter with the BROWSABLE category set, and a <data> tag set up to match your URL.
Inside your <activity>, add:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="http" android:host="www.example.com" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
and set up the action and categories how you want, and change the data tag values to something relevant to your application. This will allow your link (in this case, http://www.example.com/) to be launched in your application by the browser.
Take a look at http://developer.android.com/guide/topics/intents/intents-filters.html#ires
It's really well described how to use intent filters and why, especially in the section Common cases (http://developer.android.com/guide/topics/intents/intents-filters.html#ccases).
I have looked at the intent-filter documentation and I can't figure out this specific intent-filter.
I'm looking to use ACTION_SEND because I only want the app to show up in "Share" menus in other apps. I only want to show up in the share menu if the text of the intent is a url. For example, what is shared from the Android Browser's share menu. I don't want the app to appear in the share menu if it's just text and not a url.
What I have so far is:
<intent-filter android:label="Label">
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/*" />
</intent-filter>
However, this will receive any text, not just urls.
Thanks
You can create IntentFilter objects programmatically, and they can filter on URI schema among other things... much more control.
I thought subclassing IntentFilter would give you event more, but they made all the variations on "match" final so you can't override them in a subclass. Bah!
Eurika!
You can specify a data "scheme" instead of a mimetype. Just ask for "http" and "https" (in separate intent filters?).
<intent-filter>
...
<data android:scheme="http"/>
</intent-filter>