How to set android application "type"? - android

Is there a way to set your applications "type"? For example, If I download Opera for Android and then in another application I click a web URL, Android will ask me do I want to open the link with the default browser or with Opera. How do Opera achieve this?
EDIT specifically, how would I pass the URL into my activity?

You should read about activities and intent-filters.
Here is a good starting point: Activities, and specifically Intent Filters section.

This is done via the mechanism of Itent filters, that are defined in your Manifest.xml.
I think Opera has probably an intent filter like this set on the main activity :
<intent-filter>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
<action android:name="android.intent.action.VIEW"/>
<data android:scheme="http"/>
</intent-filter>
Then when the opening of a web page is requested via a sent Intent, the system will search through its database, which application can answer it and propose the applications to the user.

I think you have to study intent-filters. Here is the short text from android docs.
"Components advertise their capabilities — the kinds of intents they can respond to — through intent filters. Since the Android system must learn which intents a component can handle before it launches the component, intent filters are specified in the manifest as elements. A component may have any number of filters, each one describing a different capability."
Specifically for a browser I suppose that you have to register it like below:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http"/>
</intent-filter>

Related

How do I open a link from an NFC tag?

I want to write a NFC tag that opens a specific note in Google Keep when touched.
I have an URL in the form of https://keep.google.com/u/0/#LIST/<id> that does the desired action of opening the note in the installed Google Keep app on my phone when I read it with a QR-reader or click on it as a link.
When I write this URL to the tag an touch the tag afterwards, it opens in the browser. Is the NFC handler skipping other apps and opening it directly in a browser? When I clear the app-defaults for the browser, it shows a selection menu for the installed browsers after tapping the tag. Does anyone have an idea what I am doing wrong?
Links on NFC tags are not launched as intents with the typical VIEW action. Consequently, other apps may not pick those links up correctly and you will instead experience the web browser to be opened. Only apps that specifically register for the intent action NDEF_DISCOVERED will be able to receive links from NFC tags. It seems that Google Keep currently does not do this, so there's not much you can do without creating your own wrapper app that handles these URLs and passes them on to Google Keep.
You should enable deeplinks in your activity. Also you should indicate your activity NFC tag discoverable as follows. You can learn anything about deep linking via this link
<activity
android:name="ExampleActivity"
android:label="Example">
<intent-filter android:autoVerify="true">
<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:scheme="http" />
<data android:scheme="https" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>

Make a link to a url start up my app and not open embedded

I defined the following intent filter in my application in order to make it respond to url links.
<intent-filter>
<data android:scheme="http"/>
<data android:scheme="https"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<action android:name="android.intent.action.VIEW"/>
</intent-filter>
Now when I click a link in an external app (from example a link sent by sms) it opens my app in an embedded way in the current application. Meaning that if I go to background I see my app inside the sms application.
I want the link to make my application to be opened separately. This is the correct behaviour, and happens for example when choosing chrome/ android native browser as the app to open the link.
Is there a way to change that for my app as well?
You have to set the launchMode of your activity to singleTask or singleInstance. This will force the system to open a new task for your app instead of opening it in the same task as the sms-app or whatever.
It should look somehow like this:
<activity android:name="yourActivity"
android:launchMode="singleTask">
&lt/activity>
For more information, see the documentation: http://developer.android.com/guide/topics/manifest/activity-element.html#lmode

Receive content from the YouTube Android App

Is it possible to receive content just from the YouTube app?
When a user clicks the share button inside the YouTube App (and no other app/browser), my app should be listed in the share dialog.
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data
android:host="???"
android:scheme="???"
android:mimeType="text/*"/>
</intent-filter>
Can I filter by package name?
Have you tried:
<data android:host="com.google.android.youtube" />
in your intent filter?
If that doesn't work, then your best course of action would be to register it as a normal "share" broadcast receiver and log various elements of the broadcast to the console, then compare shares from YouTube to all other apps.

Run Application via link

I am working on an application where i have to create a link of my application and copy that link to text buffer and paste that link in my device in any text editor. Now when i tap on that link my application should open and show appropriate data. I don't know how to implement this i searched on internet I did not find any solution which can explain this feature implementation. give me the best way to implement this.
I have tried this but can not understand
Launch your application when a link taped
You have to use other app to start it. You should register intent-filter with other action and category in your app. The most common action should be ACTION_VIEW combine with category BROWSABLE, then you can use a url in brower or sms to open you app. The intent-filter should be like:
<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="openmyapp"
android:scheme="http" />
</intent-filter>

Invoke an Android App from a WebPage

Hi
Is it possible to invoke an Android App from a Web Page that i am displaying on the phone browser to the user. I know that this is possible from an another Android App using Intents. But i am not sure if this is possible from a WebPage.
Thanks in advance.
Intent filters with the BROWSABLE category will let you launch an application using a URI scheme. Inside your <activity>, add:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="myprotocol" />
<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 scheme to something relevant to your application.
Then inside your webpage, you can link to your application with
test link
Simply define a intent filter for a particular URI within your Activity:
http://developer.android.com/guide/topics/manifest/data-element.html
That way, that activity will be called when a corresponding link is clicked. By using a custom scheme you'll make sure that your app is the only one responding.
It's the same way the android market responds to market links.

Categories

Resources