When beside launch will android.intent.action.MAIN be fired by Android - android

If an Activity has the following filter:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Under what circumstances will an Intent matching the above filter be issued by Android?
1) During launch of the application.
2) ? Are there any other circumstances?

Anything can use that filter. The OS never uses that filter, AFAIK. Home screen applications typically use that filter. Other applications can use that filter if they so choose -- for example, here is a sample app that creates its own launcher-style list.

Related

Difference between having intent.category.HOME alone in AndroidManifest.xml and also with intent.category.DEFAULT at the same time

What are the differences between:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME"/>
</intent-filter>
and:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
See the answer Here
What is the meaning of android.intent.action.MAIN?
android.intent.action.MAIN means that this activity is the entry point of the application, i.e. when you launch the application, this activity is created.
From the docs
ACTION_MAIN with category CATEGORY_HOME -- Launch the home screen.
Also,from here
Activity Action Start as a main entry point, does not expect to
receive data.
android.intent.category.DEFAULT is mainly used for implicit intents. If your activity wishes to be started by an implicit intent it should include this catetory in its filter.
If your Activity might be started by an implicit Intent when no specific category is assigned to it, its Intent filter should include this category.
See the docs..
http://developer.android.com/reference/android/content/Intent.html
http://developer.android.com/guide/topics/manifest/action-element.html
and Another View of #CommonsWare .... in that answer also.... See it
So that ACTION_MAIN is considered an entry point for the application.
Usually, it combines with CATEGORY_LAUNCHER in an <intent-filter> to indicate an activity that should appear in the home screen's launcher, or in anything else that considers itself to be a launcher. Such "launchers" can query PackageManager, using queryIntentActivities(), to find such activities and display them to the user.
However, ACTION_MAIN can be used in combination with other categories for other specialized purposes. For example, CATEGORY_CAR_DOCK with ACTION_MAIN indicates an activity that should be considered a candidate to be shown when the user drops their phone into a manufacturer-supplied car dock.
When an Intent is used with startActivity(), if the Intent is not already placed into a category, it is placed into CATEGORY_DEFAULT. Hence, an <activity> <intent-filter> needs to specify some <category>, using <category android:name="android.intent.category.DEFAULT" /> if nothing else.

<activity> without <intent-filter> in AndroidManifest.xml

I know I need to use to enable an activity to receive an Intent like this (not main activity).
<activity android:name=".MyApp_2ndActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
However, I found it can be triggered too if "intent-filter" is removed, like this.
<activity android:name=".MyApp_2ndActivity">
</activity>
I am wondering what difference is in these 2 formats?
See here: http://developer.android.com/guide/components/intents-filters.html
The difference is the second one can only be started using an explicit Intent -- one which names the component it wants to start. The first one can be started by an implicit Intent -- one which does not specify the exact component but contains information for the system to find an appropriate match for. The intent filters are used by the system for resolving such intents.
Difference is the when we use this code:
<activity android:name=".MyApp_2ndActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
This will be the first activity triggered when you starts your application.It doesnot need any explicit intents
and when we use this code:
<activity android:name=".MyApp_2ndActivity">
</activity>
the activity will be started with the use of Explicit intent
Intent filters are used, for example, when the activity starts from a specific event on the device. Your main activity has specific intent filters. If you want your application start when NFC tag is scanned, you can specify that via intent filters.
You can read more here for example.
http://developer.android.com/guide/components/intents-filters.html

replace android intent chooser dialog

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>

Multiple android.intent.action.MAIN in manifest xml file

I am new to Android development I seen lots of tutorial where they have only android.intent.action.MAIN which is basically a start activity of the application.
But, in the android app demos, I have seen multiple android.intent.action.MAIN statements in mainfest.xml. Can anyone explain why the mainfest.xml has multiple android.intent.action.MAIN statements?
And, in which scenarios we are supposed to have multiple MAINs in manifest.xml?
They're different entry points into the program. For instance, I just created two activities, both of which had the typical intent filter
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
It turns out that my launcher screen now has two different icons for the same program, one for each different activity. This makes sense, since the MAIN/LAUNCHER intent filter essentially tells android that the activity is the app's starting activity. Nothing in android's intent filter model forces each app to have one and only one starting activity.
LAUNCHER is the category, while MAIN is the action.
MAIN defines an entry point, specifying a way the app can be launched. For example, Consider an App which has 3 activities,
SplashActivity
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
EmailActivity
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.CATEGORY_APP_EMAIL" />
</intent-filter>
PlayMusicActivity
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.CATEGORY_APP_MUSIC" />
</intent-filter>
If I click on the app icon on the home screen i.e launcher, I see Splash Activity.
If I click on a email address from a Messaging app, the system will show me a list of apps that support sending mail including my app(basically it searches for a specific combination of the intent filter provided by all applications) And when I select my app, EmailActivity will be launched.
If I open a file browser and click on an audio file, my app will be listed to open this file, and PlayMusicActivity will be opened.
So, ACTION.MAIN is the different 'enrty' points or the different 'ways' the app can be launched.
CATEGORY will tell what type of launch it can be.

How can I start the next matching activity if my app is the default one

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.

Categories

Resources