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
Related
I need to add my application to share list when I click to "Share" button on some image in gallery (for instance) and then I want to get this image in ImageView.
Share List
Thanks for help!
Intent filters inform the Android system what intents your application is willing to accept.
For images, you’d add the following to your AndroidManifest.xml
<activity android:name=".ui.MyActivity" >
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
When the gallery application tries to share an image by constructing an intent and passing it to startActivity(), your application will be listed as an option in the Android Sharesheet or intent resolver. Upon selecting your app, the corresponding activity (.ui.MyActivity in the example above) will be started. It is then up to you to handle the content appropriately within your code and UI.
More info here
you can check following link here it was mentioned exactly what you want to achieve
is there a way to replace the intent-chooser dialog? At the moment my app is having heaps of intent-filters to come close to this - but I would like to explore other options ( also only working on rooted devices is an option in this case )
I mainly want to achieve these goals:
- not having the default intent-chooser any more before my app
- being registered to all intents
also just getting closer to just one of these goals would be nice - anyone here sees an option to do what I want to do?
This is supported by the system. All you need to do is to create an Activity that has an Intent.CHOOSER Intent filter.
Here is the definition of the one by default in Android:
<activity android:name="com.android.internal.app.ChooserActivity"
android:theme="#style/Theme.Holo.Dialog.Alert"
android:finishOnCloseSystemDialogs="true"
android:excludeFromRecents="true"
android:multiprocess="true">
<intent-filter>
<action android:name="android.intent.action.CHOOSER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
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.
I have an activity that works as a hook for various intents. Specifically, the VOICE_COMMAND and CALL_PRIVILEGED. (It is a requirement to use these.)
<activity android:name=".MyActivity"
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.VOICE_COMMAND" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.CALL_PRIVILEGED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="tel" />
</intent-filter>
</activity>
I ask the user to set my app as the default action for these intents so they don't have to select it every time. This is also a requirement.
The problem is that in certain cases I want my activity to work transparently and pass the intent to the dialer or other app. This should be selectable by the user. I achieved this by using getPackageManager().setComponentEnabledSetting(myCompName, isEnabled, PackageManager.DONT_KILL_APP) on my activity in certain places of the code.
Is there a more elegant way to do this? I tried startNextMatchingActivity(getIntent()) but that does not start anything (returns false). Does this mean that if there is a default action, then everything else is ignored from the intent resolution?
Currently (on Android 2.3) there seems to be no other way of forwarding the intent than doing it manually. Additionally, to send CALL_PRIVILEGED intent the app must have special permissions that only system apps have. (The app will receive not allowed exceptions otherwise.)
All in all, the intent must be converted to some other intent that my app can send and start the next activity manually by retrieving the list of applicable activities from the PackageManager.queryIntentActivities() API.
Instead of declaring a pre-determined launcher activity in my manifest using an intent filter:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Could I, instead, be given programmatic control over the activity which gets run when the application launches?
I'm not able to find anywhere in the documentation which says I must use the intent filter approach... but I also don't see any discussion of the alternative(s).
http://developer.android.com/guide/topics/fundamentals/activities.html
http://developer.android.com/guide/topics/intents/intents-filters.html
Thanks.
As far as I know, it's not possible. Android creates or sets up the hard link of the App icons to their respective activities by looking at the manifest. If you don't set it, you will not find any icons/shortcuts for your app after you install it.