I have two android apps
one is for user type 1, it's a launcher app, the user will use this app as a default launcher
The second one is a regular app for user type 2, the user opens the app and uses.
After onwards I have merged two apps into a single app. It's all working fine. But both the users are seeing a screen like this choose which app to be a launcher
Can anyone tell me is it possible to make the app as launcher only for user type 1?
You can declare the launcher component (i.e. the activity receiving the HOME intent) as disabled :
<activity
android:name="my.launcher.Class"
android:enabled="false"
... >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</activity>
Then programatically enable it for user 1, using PackageManager.setComponentEnabledSetting :
ComponentName cn = ComponentName.unflattenFromString("my.app.id/my.launcher.Class")
packageManager.setComponentEnabledSetting(cn,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP)
Related
On Android 9 and previous versions, OS was keeping the Open by default setting as Some defaults keep if the user makes your app as the default launcher once. Thus, when the application was to become the default launcher for the second time, the system did not ask the user again.
But for Android 10 and 11, if some apps became the default launcher, the system marks the Open by default setting of all other HOME apps as No defaults set.
So the system annoys the user by asking if they want to set the app as the default launcher each time. How can I prevent this?
val intent = Intent(Intent.ACTION_MAIN)
intent.addCategory(Intent.CATEGORY_HOME)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
applicationContext.startActivity(intent)
Manifest:
<activity android:name=".LauncherActivity"
android:launchMode="singleInstance"
android:stateNotNeeded="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I have a requirement to do an app to function like this.
Its an android application and it should have 2 launching methods.
One is to proceed the function directly when touching the icon.
Another icon should be there to give the setting to the same app to set the setting the settings of the android application.
Basically the app should work like the screen off and lock app in the market.
How can i achieve these 2 things in one app? When i install the app, i need to have two icons, one to do the functionality directly and other to set the settings of the application.
I believe you are trying to have to separate launchers (icons to start apps) in your app, launching two different activities. This is easily achieved within your manifest. Create two activities, say MainActivity and SettingsActivity and then declare them in manifest as launch-able - with different titles:
<activity
android:name=".MainActivity"
android:label="#string/main_activity_title"
android:icon="#drawable/main_icon">
<intent-filter android:label="#string/main_app_title">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SettingsActivity"
android:label="#string/settings_activity_title"
android:icon="#drawable/settings_icon">
<intent-filter android:label="#string/settings_app_title">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
When your app is installed, there will be two icons created: one to start the MainAcivity and another one to start SettingsActivity.
I have an application where I need to provide a additional icon acccessible in applications to launch an activity from the same application.
So that when application installs it shows two icons in the applications list, one icon to launch the app is already there, how to have the other icon and then how can I start the required activity from that icon/shortcut.
add this in the manifest file inside the activity tag which you want to show in the launcher
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
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.
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.