i am creating a simple app for a project that comes with an image and above it a button when you press the button the image becomes the wallpaper of the phone.
This i have done however for my project i need the wallpaper to be removed if the app is uninstalled how do i do this?
Save your images here this folder will be deleted when you uninstall the app
If you look at the Android Documentation for the Intent ACTION_PACKAGE_REMOVED, you will see that this broadcast action will be received by any other interested application (other apps who are registered to receive this broadcast), other than your own application.
Quote from the developer.android.com site:
Broadcast Action: An existing application package has been removed
from the device. The data contains the name of the package. The
package that is being installed does not receive this Intent.
Unfortunetaly, because your app can never detect that it is being removed, you cannot trigger a specific function that will change the Wallpaper on the device. If it were possible (which it isn't), a simple function (code follows) would have shown the Select Wallpaper chooser to the user.
Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER);
startActivity(Intent.createChooser(intent, "Select Wallpaper"));
It is something the user will have to manually change once he / she has uninstalled your application.
That being said, as far as deleting all your app created files are concerned, let Android handle that for you. Use one of these options depending on the API:
API greater 8 or greater: getExternalCacheDir
API 7 or lesser: getExternalStorageDirectory.
Something like this will let you determine which one to use depending on the device API:
int currentAPIVersion = android.os.Build.VERSION.SDK_INT;
if (currentAPIVersion >= android.os.Build.VERSION_CODES.ECLAIR) {
// USE getExternalStorageDirectory
} else {
// USE getExternalCacheDir
}
Related
I'm currently create an application that have the possibility to updated from own code thanks to a downloaded .apk from a server.
I would like to know if the update/Install of the app is successfull. Because currently the update working fine but i don't know if the installation/update is ok or not, if the installation face a problem or if the user cancel install or somethings else. So i need to have a callback "installFinish(boolean isOk)".
i search for a day but i don't find solution for my problem.
I read lot of things, particulary this :
How to find out when an installation is completed
or this :
Android - Install Application programmatically with result
but is not what i seach.
This is my code for update my app
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file.getAbsoluteFile()), "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
((Activity) context).startActivity(intent);
EDIT
I tried this https://stackoverflow.com/questions/29175722/how-to-get-onactivityresult-called-from-action-view-intent
but it's not working for me for two reason i think:
I don't know whether the user pressed Cancel
onActivityResult is never call after updated the same app, maybe because it's the same app which updated the app who launch the intent is kill. ?
Maybe the last reason it's the same reason why i don't receive broadcastevent such as listening for ACTION_PACKAGE_ADDED in the app who launch the update.
Maybe i can call the method when the first time the application is launch, it's like install is successfully because the app is started.
Heres a work around which we use:
Implement a dummy provider and override onUpgrade().onUpgrade is called whenever database is upgraded.U will need maintain one to one mapping between database version and app version.
I will prevent some application to be deleted from the phone.
Now, I can get current top activity name using ActityManager and check if it is com.android.packageinstaller.UninstallerActivity, than do additional logic for checking which package will be deleted. but I can't get UninstallerActivity object, and more - I can't get Intent passed to com.android.packageinstaller.UninstallerActivity (which will provide package name for me).
Seems like this isn't possible with standart Android API way. maybe it's possible using hidden API and reflection.
Any ideas?
Edit: I'm writing Launcher application, which will be distributed manually in hotels. I will have functionality which prevents from deleting my Launcher application from the phone, because mobile phones will be given in rent, and Launcher replacement isn't possible.
Note: The phone will be rooted!
How to check if intent or app has started ?
My use case is I am showing up notifications through my app and I want to clear them all via myBuilder.cancelAll() if default messaging app has started since my app shows sms notifications. So I am kind of looking for something like:
if (smsAppStarted) {
myBuilder.cancelAll();
}
Thanks
To check if an app has started:
Get the package name of the sms app you want to check.
Then refer to my answer here:
Android how to know an app has been started and range apps priority according the starting times
By using that code, the list taskInfo will contain the list of all apps currently running. Search that list using the package name of the sms app. If it is present in that list, it means that that app has started and currently running.
If I get you right, you need to determine, if another app is currently running. If so, then use this solution.
I've been searching and I couldn't find a topic that could clarify me 100%.
My question is: How can I launch an android's app preferences activity (from Contacts, Messages, ...) on my own app?
I give an example:
Imagine I'm developing an app which allows the user to quickly access to Message's Settings. I don't need to send or receive any information, I only need to open the activity, create a shortcut for it.
Someone knows if this can be done and even opening specific locations of the apps?
You don't need to know any specific locations or specific apps for these actions, simply look into Intent.ACTION_PICK.
Picking a Contact: get contact info from android contact picker
Picking a picture: How to pick an image from gallery (SD Card) for my app?
The best answer in this thread has the solution:
android: how do i open another app from my app?
Also check:
http://android-developers.blogspot.com/2009/01/can-i-use-this-intent.html
To open settings, you can try:
startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS, 0));
There is no difference in writing in code an Explicit Intent which will go to a specific activity of your app and using the same format to go to a specific activity some other app. A few things to be aware of: (1) The receiving activity may be expecting particular data and fail otherwise. (2) The standard apps you are considering like Contacts, Messages while you can find the source for them in the Android Open Source Project (AOSP) may be changed by the manufacturers so that the activity names and necessary extra data could be different.
In order to maintain as much compatibility between all of the different Android manufacturers, you should stick to the standard implicit intent with the appropriate action/data.
This question already has answers here:
How can an app detect that it's going to be uninstalled? [duplicate]
(4 answers)
Closed 7 years ago.
I have developed an Android app.
Now I want to perform a few operations (i. e. - Reset the settings etc.. ) at the moment the app gets uninstalled from the phone.
Is it possible to reigster a listener or a function that is called at the moment the app is removed?
Sadly android at the moment does not give you a possibility to perform code at the moment your app is uninstalled.
All the settings that are set via the SharedPreferences are deleted together with everything in the Application Data an Cache folder.
The only thing that will persist is the data that is written to the SD-Card and any changes to phone settings that are made. I don't know what happens to data that is synchronized to the contacts through your app.
You cannot get control when your application is uninstalled -- sorry!
Since API level 8 you may use Context.getExternalFilesDir(). In theory any data placed here will be removed when the application is uninstalled.
http://developer.android.com/reference/android/content/Context.html#getExternalFilesDir(java.lang.String)
When user uninstall android application in his mobile the PACKAGE_REMOVED receiver will call. You can get uninstalled app package name use intent,getDataString()
if (intent.getAction (). equals ("android.intent.action.PACKAGE_REMOVED")) {
String packageName = intent.getDataString ();
System.out.println ("uninstall:" + packageName + "package name of the program");
}
See complete example in this link.
http://foryouneed.blogspot.in/2014/08/android-listener-application-to-install.html