I am trying to remove all recent tasks through a program. Before posting a question, I googled it, but no luck at all.
I tried to use ActivityManager.killBackgroundProcess(pckagename), but it also does not remove the task from a recent task list.
I also tried the link
Android, how to clear the recent task list which could get from Home button in most phone? Reflection is a possible way?
I always get the following exception
java.lang.SecurityException: Permission Denial:
removeTask() from pid=23297, uid=10051 requires
android.permission.REMOVE_TASKS
Even if I already specified the android.permission.REMOVE_TASKS permission in the manifest.
How can we clear the list of recent tasks programmatically, so that the user can see no recent tasks in a recent task list?
REMOVE_TASKS is a signature-level permission. It can only be held by apps written by the developers of the device firmware, such as a device manufacturer or ROM mod author.
Try this out in android manifest inside the launcher activity:
android:excludeFromRecents="true"
I just met with the same problem. My duty was to remove a 3th party app from recent list.
Okay, I don`t know how clear the recent list, but I know, how not to put your app there.
start it with: FLAG_ACTIVITY_NO_HISTORY flag .
This worked for me, I hope I can help with it for you.
details:
min SDK level 14
Cheers,
In your AndroidManifest.xml, you need to add this:
uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"
Related
I've implemented a short Flutter App which is requesting and checking the camera permission which works as expected. But, when manually changing the camera permission from the app settings, for both Android and iOS, it will restart my app. I need to mention that I've added in AndroidManifest.xml and Info.plist the required keys for camera. One interesting thing is that for the location the behaviour is fine and the app does not get restarted.
For permissions I'm using the permission_handler flutter library.
I don't know if is a flutter issue or a general mobile known behaviour but if someone knows more please let me know. If someone need some code example I can also provide this. Thank you.
It doesn't get 'restarted', it gets killed. Meaning, it will run from app launch the next time. This is because some permission settings cannot be changed while the App is running. This is by design.
I want to make a app where user can set the time for switch off the phone and switch on (like user set the time for evening 7 pm to off and morning 7 am to switch on automatically). Is there any possible way to perform this action without rooted ?
Please suggest me.
And also try to give
<uses-permission android:name="android.permission.REBOOT"/>
permission but it's also not possible for me to granted as manually and runtime.
This permission is not available to third-party apps (see its documentation).
Sorry, this is simply not something android will let you do – unless you root the device, of course.
You cannot finish and restart the whole app. I suggest you to keep only one activity at time (good practices), and you can restart it just with:
Intent intent=getIntent();
finish();
startActivity(intent);
This is an alternative because of the title of your question, but what you actually need is to create a Service or a Broadcast to achieve the functionality you need.
Tip: I recommend you to search alarm apps code examples.
Hope it helps you.
Well, hello..
I have a question, how would you correctly use this
"ActivityManager.killBackgroundProcesses(String packageName)"
I have tried to replace packagename with a package, for now let's call it com.example.package.
It doesn't seem to be compiling it as it pops up with errors (I am new to Android app developing)
Would appreciate any help! =)
You must have a special permission to kill background processes from your application. Add the following permission in your manifest.
"uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"
The above permission enables to kill any background process running for the package name provided in "ActivityManager.killBackgroundProcesses(String packageName)"
I'd like to know if there is any way to determine the permissions my app needs.
There is a similar question here:How do I determine why my Android app requires certain permissions?
But the answer states, that you basically have to find out yourself and I can't believe this.
Is there really no way to tell Eclipse to take a look at my code and determine the needed permissions or something like this? There should be no problem to automate this.
Or is there a way to test permissions on a device. When I install my app on my local device I'm not asked for any permissions.
Any help is really welcome.
This should work:
boolean crashes = true
while (crashes) {
ReadLogCat()
AddPermissionFoundMissingAccordingToLogCat()
crashes = TryAgain()
}
PS: This is pseudocode ;)
PPS: You didn't copy this to Eclipse, did you? Just kiddin' ;)
Believe it.
The app crashes and tells you the reason why: it expected some permission(s) declared in its manifest file.
It normally tells you in 2 ways: in a Dialog (FC Dialog) and in the LogCat.
You have to define permissions according to what your apps doing, if it's accessing the internet, it needs permission to do it. If it wants to locate you via GPS, it needs a permission for it and no you can't automate it, not officially anyway.
Think your app as a virtual child, you need to grant it permission to do stuff or else it won't do anything. So you have to pretty much decide yourself.
But you need not worry, if you're missing a permission, the log will let you know which one it is.
well i won't consider this as official solution for this problem
usually when i miss any permission in my application say i am using internet connectivity or get tasks but i didn't declared them in manifest
when i run my app i get it in log cat saying internet permission and get tasks permissions are required for this app to run
hope that answer your question
Is there really no way to tell Eclipse to take a look at my code and determine the needed permissions or something like this?
If you have a test suite that adequately tests your app, running the test suite will tell you the needed permissions, because your tests will crash if you do not have them.
Or is there a way to test permissions on a device. When I install my app on my local device I'm not asked for any permissions.
The permissions that you see on install are based on your <uses-permission> elements in your manifest, not some analysis of the app beyond that. Hence, this will not help you. That being said, installing your app by any means other than adb, such as downloading the app from a Web server, will pop up the permissions dialog, so you can see what prospective users will see at install time.
I know it's a simple question but I can't find any answer. Well actually it's three related questions:
If my code requires a uses-permission manifest element, does Eclipse automatically add it to the manifest?
If Eclipse doesn't automatically add it, how do I know which permissions my app needs? Of course there is this list, but it's hard to go though this list checking if what my app does falls within each of these permissions.
If Eclipse doesn't automatically add the permission and I fail to do it, how will I find out? Will the app fail to install on the emulator? Will it install on the emulator but be force-closed when trying to access something it doesn't have permissions for? Or do I have to install the apk on a real device in order to find out?
If my code requires a uses-permission manifest element, does Eclipse automatically add it to the manifest?
No.
how do I know which permissions my app needs?
Generally, by reading the JavaDocs, which do a decent job of pointing out what permissions you need. Otherwise, you will find out in testing, when your app crashes with a SecurityException.
If Eclipse doesn't automatically add the permission and I fail to do it, how will I find out?
See above.
Will it install on the emulator but be force-closed when trying to access something it doesn't have permissions for?
Correct.
Eclipse will not add permissions automatically. However, if you try to use a feature that requires permission, you will be made aware of the missing permission. Here's an excerpt from android resource page on Permissions: Link
Often times a permission failure will result in a SecurityException
being thrown back to the application. However, this is not guaranteed
to occur everywhere. For example, the sendBroadcast(Intent) method
checks permissions as data is being delivered to each receiver, after
the method call has returned, so you will not receive an exception if
there are permission failures. In almost all cases, however, a
permission failure will be printed to the system log.
Your third question is answered by:
In almost all cases, however, a permission failure will be printed to
the system log.
Just in case you're wondering about what you would see in Logcat:
11-20 08:08:47.766: E/AndroidRuntime(9380):
java.lang.SecurityException: Need BLUETOOTH permission: Neither user
10111 nor current process has android.permission.BLUETOOTH.
Eclipse does not automatically add the uses-permission to your manifest. I once had forgot to add a permission and had my app fail when it got to that part of the code. I can't remember the exact error but it did mention that a permission was required to use the method I tried using and I believe that it told me what permission.
If you don't add one in then you will soon find out.