for example, in whatsapp someone send own location and when we click to message system opens choise dialog with map apps that can open location like google map, yandex map and others. I want that my map app also be there. Other words, I want that system recognize my app as map app and when user click to location in whatsapp or other apps my app appear in system choise dialog. How can I configure my app to open location? I searched and in forums and android documentation they recommend to use implicit intent for it. But they dont show how to configure app that shows in system choises. I heard about mime-types but in documentation there are no mime-type for location.
You need to add an intent-filter to your activity that allows it to respond to map URLs. In your Androidmanifest.xml:
<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="http" android:host="maps.google.com" />
<data android:scheme="https" android:host="maps.google.com" />
<data android:scheme="geo"/>
</intent-filter>
To retrieve the URI:
protected void onCreate(Bundle savedInstanceState) {
Intent intent = getIntent();
Uri data = intent.getData(); // Here you will receive the URI
// ...
}
Implicit Intent's are more of like Your app to other apps sort of thing and you're aiming for the reverse version (Other apps to your app). What you are looking for is Intent Filter. As per the docs:
To allow other apps to start your activity, you need to add an <intent-filter> element in your manifest file for the corresponding <activity> element.
Cheers! :)
Related
I am trying to make a video player app. I can play video by opening my app manually. But I want to show my app as an option like below picture:
in short, when I click any video file in file manager, this will show my app as an option for playing that video. When user click on my app this will open a particular activity and start playing that file. How can I do this?
add intent filter to activity.
very similar to this.
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="video/*" />
</intent-filter>
also see this Forcing an app chooser
Read how to achieve this in official documentation
You need to put an intent filter in your manifest.xml. This tells the OS which types of media/ files your app is capable of handling. When you click a video file in file manager, Android issues an implicit intent . This basically puts out a wanted ad (excuse the analogy) to other apps that the file needs to be handled. When this happens, if your app has the capability to handle this file/ media type, it will respond. From here, if there is only one capable app, it will be selected for the task. If there are multiple capable apps, all of them will be added to a list, which is then displayed to the user (the list in the image you posted above.)
Add the below code to inside activity(that you want to open) inside manifest:
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="video/*"/>
<data android:scheme="content"/>
<data android:scheme="file"/>
</intent-filter>
use below code to your activity to get the uri of your file. I have tested the path in exoplayer.
Uri uri = getIntent().getData();
If you're an avid user of stackexchange android app, you might have noticed this: make a Google search with chrome, if the SERP contains any link from any stackexchange site and you click it, it will automatically open stackexchange app and the clicked question will be loaded.
See an example :
Please, how can I achieve something similar with my app?
You should see Deep-linking chapter
https://developer.android.com/training/app-indexing/deep-linking.html
Define intent filter for the activity (which is going to handle the url ) you want to launch in Manifest
<activity
android:name="com.example.android.LinkHandlerActivity"
android:label="#string/title_gizmos" >
<intent-filter android:label="#string/filter_title_viewgizmos">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Accepts URIs that begin with "http://www.example.com/gizmos” -->
<data android:scheme="http"
android:host="www.example.com"
android:pathPrefix="/gizmos" />
<!-- note that the leading "/" is required for pathPrefix-->
<!-- Accepts URIs that begin with "example://gizmos” -->
<data android:scheme="example"
android:host="gizmos" />
</intent-filter>
And then handle link in activity like this
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent intent = getIntent();
String action = intent.getAction();
Uri data = intent.getData();
}
It is called Deep App Linking. Here is the tutorial. But, I read some stuff a while ago, that Google no longer use Deep App Linking. I guess they use App Indexing now. Here is the info about App Indexing. Note that, maybe you can use Deep App Linking for now, but it can be deprecated. You can google it for further info.
You need to add deep app links to your webpage html files. Which when clicked from mobile browser, sends an intent to app. In Deep Indexing you don't need to do that I guess.
Sorry, I could've commented that, but my reputation is not enough.
This question already has answers here:
How to implement my very own URI scheme on Android
(5 answers)
Closed 7 years ago.
I want to make an android app that can be used as a default application for opening a certain kind of link (like if I click http://facebook.com it will show me suggested app to open that link, browser or facebook's app)
These are called Implicit Intents
Assume you want to open your app on web link click with link "myApp://someapp"
then in your App Manifest
<activity android:name="MyActivity">
<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" android:host="path" />
</intent-filter>
</activity>
Whenever you click the above link, it will suggest to open your app.
If you want to developed application that allow the other application to complete the action using your application, for example in your case you want to handle the any of url user click, your application will be listed for complete the action. You have to create the activity that will handle the deep linking. For that you need to add some attributes to your handle activity in your android manifest. see below example
The following XML snippet shows how you might specify an intent filter in your manifest for deep linking. The URIs that start with “http”
<activity
android:name="com.example.android.BrowseActivity"
>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Accepts URIs that begin with "http://www.example.com/gizmos” -->
<data android:scheme="http"
android:host="www.example.com"
android:pathPrefix="/gizmos" />
<!-- note that the leading "/" is required for pathPrefix-->
<!-- Accepts URIs that begin with custom url "example://gizmos” -->
<data android:scheme="com.example.android"
android:host="gizmos" />
</intent-filter>
</activity>
Once you've added intent filters with URIs for activity content to your app manifest, Android is able to route any Intent that has matching URIs to your app at runtime.
Once the system starts your activity(BrowseActivity) through an intent filter, you can use data provided by the Intent to determine what you need to render. Call the getData() and getAction() methods to retrieve the data and action associated with the incoming Intent. You can call these methods at any time during the lifecycle of the activity, but you should generally do so during early callbacks such as onCreate() or onStart().
Here’s a snippet that shows how to retrieve data from an Intent inside BrowseActivity:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent intent = getIntent();
String action = intent.getAction();
Uri data = intent.getData();
}
Let me know if you need more help on this point thank you.
Im looking for a way to make a link between contact and Android Application. An example of this is Whatsapp, this application binds to a contact and makes it possible to launch the whatsapp application with the number as parameter. I have not been able to find a way of accomplishing this, and was wondering if there was someone with expierence in this area.
Your help is very much appreciated
I didn't try this, but I hope my answer will be helpful for you.
To clarify, you want your app was in the 'Connections' section as Whatsapp app:
In this case, you should use Account Manager
If you go to the phone Settings in the "Accounts and Sync" you should see all of the custom accounts registered on your phone:
Sorry, for not providing exact code snippets, but I hope this was useful for you, and you can Google your question (looking for Account Manager).
Maybe these links will be useful for you too:
create custom account android
Custom Account Type with Android AccountManager
Intent-Filter is the way to go!
In your AndroidManifest.xml you have to tell Android that your app can respond to such an Intent.
Example:
<application ... >
<activity ... >
<intent-filter>
<action android:name="android.intent.action.SENDTO" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="sms" />
<data android:scheme="smsto" />
</intent-filter>
</activity>
</application>
Than your Activity can access the Intents data when called.
Example:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// get intent-data
Intent intent = getIntent();
if (Intent.ACTION_SENDTO.equals(intent.getAction())) {
Toast.makeText(this, intent.getDataString(), Toast.LENGTH_LONG).show();
}
// close activity
finish();
}
With this code you can choose your App as the receiver whenever another App (e.g. Contacts) fires such an Intent.
Example to fire such an Intent (Screenshot from Contacts):
I don't know if many people have tried this but I am trying a build an app that requires user to tap on a link on the sms he/she receives and this will launch the android app. Is it possible to do in android? If yes, how can I do this? I know this can be done in IOS. Any suggestions or help will be appreciated. Thank You.
In you Manifest, under an Activity that you want to handle incoming data from a link clicked in the messaging app, define something like this:
<activity android:name=".SomeActivityName" >
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.VIEW" />
<data android:scheme="com.your_package.something" />
</intent-filter>
</activity>
The android:scheme="" here is what will ensure that the Activity will react to any data with this in it:
<data android:scheme="com.your_package.something" />
In the SomeActivityName (Name used as an illustration. Naturally, you will use your own :-)), you can run a check like this:
Uri data = getIntent().getData();
String strData = data.toString();
if (strScreenName.equals("com.your_package.something://")) {
// THIS IS OPTIONAL IN CASE YOU NEED TO VERIFY. THE ACTUAL USAGE IN MY APP IS BELOW THIS BLOCK
}
My app's similar usage:
Uri data = getIntent().getData();
strScreenName = data.toString()
.replaceAll("com.some_thing.profile://", "")
.replaceAll("#", "");
I use this to handle clicks on twitter #username links within my app. I need to strip out the com.some_thing.profile:// and the # to get the username for further processing. The Manifest code, is the exact same (with just the name and scheme changed).
Add an intent-filter to your app that listens for links that follow the format you want your app to be launched on.
However, this will be a global listener, and any link that fits the format even outside the SMS app will trigger your app. So if the user taps a similar link in the web browser, your app will attempt to respond to it.
Additionally, if there is another app besides yours that can handle this link, Android will create a chooser that allows the user to pick whichever app they want to use. There is nothing you can do about this, except suggest that the user make your app the default handler for such links.
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE"
<data android:scheme="https" android:host="${hostName}" android:pathPattern="/.*" />
</intent-filter>
Previous answers are OK but don't forget to specify the pattern.
See more details here.
Also define your hostname inside Gradle file like:
android {
defaultConfig {
manifestPlaceholders = [hostName:"subdomain.example.com"]
}
}
More info about manifestPlaceholders here.