We know how to hide an app in app drawer (launcher) referring to hide one application in application menu of android , however, could we hide app itself within its code? I mean is it possible to remove activity's intent filter
<category android:name="android.intent.category.LAUNCHER" />
dynamically within its code.
No. The manifest is read by the Android package manager system when it is installed. Afterwards, these values are read from it's own datastore and not from the manifest so without modifying the PackageManager or installing a different version of the app, these settings cannot be changed.
AFAIK, this isn't possible. The manifest states what your application can or can't do.
Think about permissions : they are required for proper code execution, but you can't change them once your application is installed. That should be the same for intent filters.
Related
As per changes in Android Lollipop, reference :
StackOverflow Question
Cheese factory blog
I expect that when I start an activity of other application from my application, it should open in a new task even if the behavior is default (launchmode is standard). So, I made 2 test apps to verify the same behavior. But surpirisingly, the other app always opens up in my app's task, if there's no launchmode specified. I've tested this on Xiaomi Redmi Note 3 (5.1.1), Marshmallow emulator (x86), and the behavior is same for both. I'd appreciate some help on this, and also a link for reference from Android developer's site.
Some code :
Launching app :
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
startActivity(intent);
break;
App to be launched :
<activity android:name="com.android.sample.launchdemo.ActivityB">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
On a button click from launching app, the intent is fired and activity B successfully opens up, but in the same task. Thanks in advance for any help/suggestions.
After looking through the documentation, the feeling I have is that standard mode works the same way as it did before Android 5.0 (Lollipop). The cheese factory blog post was the only one that specified that action and even in my own experience standard launch modes have opened an activity in the same task it was sent in (unless intent flags were passed through). Someone correct me if I am wrong but it is not specified in Android documentation that standard mode would open a new task. From the Android documentation:
"standard" (the default mode): The system creates a new instance of the activity in the task from which it was started and routes the intent to it. The activity can be instantiated multiple times, each instance can belong to different tasks, and one task can have multiple instances. See full documentation
For what you are looking for, when firing off the Intent, the only way to guarantee a new task is use the flag FLAG_ACTIVITY_NEW_TASK. You can set this by calling either intent.setFlag(Intent.FLAG_ACTIVITY_NEW_TASK) or intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) (the latter is for chaining flags together because that method will return the intent).
After doing more research, the only change (relating to this) that appears to be made in Android 5.0 Lollipop is that the recent apps screen can show multiple instances of an activity.
In previous releases, the recents screen could only display only one task for each app that the user interacted with most recently. Now your app can open more tasks as needed for additional concurrent activities for documents. This feature facilitates multitasking by letting users quickly switch between individual activities and documents from the recents screen, with a consistent switching experience across all apps. Examples of such concurrent tasks might include open tabs in a web browser app, documents in a productivity app, concurrent matches in a game, or chats in a messaging app.
To me this seems like the only change relating and the post (cheesefactory and SO) have documentLaunchMode set to create new tasks for each activity (which very well could be the case considering the cheesefactory had a "Gallery" app). Documentation on concurrent documents and documentLaunchMode. documentLaunchMode and the flag FLAG_ACTIVITY_NEW_TASK can be configured to do similar things documentLaunchMode is preferred.
I've found the documentation below.
https://developer.android.com/guide/components/activities/recents.html
=> when the user is using their browser, and they tap Share > Gmail. The Gmail app's Compose screen appears. Tapping the Recents button at that time reveals Chrome and Gmail running as separate tasks. In lower versions of Android, all of the activities appear as a single task, making the Back button the only means of navigation. Figure 2 shows how the Recents screen looks in Android 5.0 and higher, versus lower versions of the platform. The image on the left screen for Android 5.0 and higher, and the image on the right shows how it appears in lower versions of Android.
and refer to the following link.
Lollipop: making my activity stay in the task that launched the share intent
=> By default, launchMode of myfirstapp.MainActivity is "standard" and any intent flags weren't set.
But after myfirstapp.MainActivity is started through share action of Album, the intent flag contains FLAG_ACTIVITY_MULTIPLE_TASK, FLAG_ACTIVITY_NEW_DOCUMENT.
When an activity is started through share, an activity which contains share in its Toolbar just sets Intent to its ShareActionProvider, and then ShareActionProvider starts an activity with this Intent - in this case, myfirstapp.MainActivity.
So I think that from Lollipop, the system begins a new task for the activity from a different app whose launchMode is "standard" only when the activity is started through share action.
I want to make an application in which we show the list of all apps which is installed in my phone with checkbox. When user checked the any application then that apps should be show on Launcher. Otherwise apps should be hide from Launcher.
Unless you code a launcher app too, it's not possible. Other launcher's will simply look at the apps manifest (using package manager) if it declares launcher intent or not.
In the case where both launcher and settings are in same app, best solution will be to use a shared preferences file:
Set<String> blacklistedApps;
//--add package names--
blacklistedApps.put("com.useless.uselessapp");
//--save as a preference--
SharedPreferences.Editor.putStringSet("blacklisted",blacklistedApps).commit();
//--read preference--
blacklistedApps = SharedPreferences.getStringSet("blacklisted",new Set<String>());
I want to install another applications from my App, likes Google Play. When applications installed, I want to remove their icon launcher (my application will manage them). Can I do it?
No, you cannot manage another APK's files from within yours, as it would be a security risk. If you wanted to manage the apps from your app however you could create intents to launch them from your application using where (just replace the String with the name of the launch activity defined by the applications android manifest):
Intent launch = ("otherApplicationActivity");
startActivity(launch);
you can make launcher icon for app in mainfest.xml
` <application
android:icon="#drawable/ic_launcher"
/>
`
I can hide icons from a Menu, but then the app can not run.
Actually, it is a monitoring app. Can anybody help me?
What I want to do is hide the icon when app is installed on device I tried several ways but then app activity not show and I get error:
[2012-07-13 12:28:40 - Demo App] No Launcher activity found!
[2012-07-13 12:28:40 - Demo App] The launch will only sync the application package on the device!
why not just use a service? and/or a broadcast receiver?
anyway, so it wont install an icon, use this:
remove this from the intent filter in your manifest.
<category android:name="android.intent.category.LAUNCHER" />
you might wanna add a receiver so reboot wont be required.
How do I make my android app the default application to open a certain file type?
I tried to clear the defaults but the option is greyed out, does anyone know how to do this?
I want to make my app open with my something.whatever files in android.
You cannot force this, and you shouldn't be able to. What you can do is make known your app can open the filetype. The user gets the standard "what program do you wish to use" dialog, and the user can select something as default.
If the user has allready selected a default, he/she needs to undo that before the dialog appears (obviously, otherwise a 'default' wouldn't have a lot of effect, now would it?)
You can tell the world (aka: android) that you want to open a certain file type by adding an intent-filter. What you basically do is put in your manifest that an activity in your app knows how to handle the filetype (or website/protocol etc). That's quite easy to find, a random question here on SO about the same issue would be: Android intent filter for a particular file extension?
This subject has already been covered here: Register to be default app for custom file type
Add it to you intent-filter:
<intent-filter >
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/pdf" />
</intent-filter>
In Android, how to associate file with a different program.
I'm using a "Droid Maxx" with Android Version 4.4.4
How to make a something.html file open with a file editor instead of firefox after you've associated firefox to always be associated with *.html files.
You have to clear out the default setting for the app that has associated with a filetype.
Do this
Go to "Settings". It's in the app list.
Under Device, click "Apps".
Scroll down and click Firefox.
Under the "Launch by default" entry, click "Clear defaults".
Open your something.html file again.
Once again you are presented with a choice with what kind of program you want to open this file with.
If you want to associate and disassociate file types with apps indivdiaully:
There is a third party app called: Default App Manager Lite:
https://play.google.com/store/apps/details?id=com.appiator.defaultappmanager
Then you can run the program and manage your filetype -> default app associations individually.
I think in android every app/activity must have some intent actions and categories in its manifest file. In this intent settings only you have to make your app as default.
Even you write default in manifest, if any other apps found with same intent settings, android system will display all apps with same settings. user has to select one of them, there only it provide one check box to make one app as default for next time onwards. If user didn't check it the list will be displayed every time user opens the file.
I hope it may help you.
Try this
Intent i = new Intent();
i.setAction(android.content.Intent.ACTION_VIEW);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setDataAndType(Uri.parse("file://"+path),
"application/vnd.android.package-archive");
startActivity(i);
The path variable is your path.