Is there on install event in android? - java

Is there some event/receiver or something for handling first execution after installation or directly after installation? Or Do I need it emulate with preferences?

There is the ACTION_PACKAGE_ADDED Broadcast Intent, but the application being installed doesn't receive this.
So checking if a preference is set is probably the easiest solution.
SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(this);
boolean firstRun = p.getBoolean(PREFERENCE_FIRST_RUN, true);
p.edit().putBoolean(PREFERENCE_FIRST_RUN, false).commit();

See Get referrer after installing app from Android Market - you can put whatever you want in there. I believe this is how Plan B works - the app that can send back your phone's location after it's stolen, that you install from the website after it's been stolen.

I don't think there is such a thing, and I don't think this would be a good idea : usually you have to handle not only installations but some updates (say : a new version with features) or the proper initialization of some resources.
For the resources, the best way is to check them directly.
For the version, I use the database, it's so easy.

The SQLiteOpenHelper's OnUpgrade method is called when the database version changed. I suppose this could be used to do other things than just handling the new schema.

Related

Is there a broadcast/intent when Android OS update happens?

I was looking for a hook, like action intent, which can call my app (having a service), when an OS update has happened. (The boot when OS update has happened.)
I checked the standard action content on the Android website, but couldn't find one which I can use directly.
Thanks.
There is no special version of ACTION_BOOT_COMPLETED or other Intent actions that is unique to a reboot after an OS upgrade.
When your service gets control for any reason, compare the current Build information to some cached copy that you maintain, to see if there is a difference that matters to you.
You can check firmware version by Build.RADIO or Build.getRadioVersion() on each system reboot to find out if update occured.

Can I write to Android SharedPreference for a different package?

I've written a game which I intend to upload to the marketplace as a free demo, and I intend to offer a full version for a buck.
I'd like to make the download for the full version just a simple unlocker which writes a value to the SharedPreferences for the demo.
When the demo launches it reads its shared prefs and if the value is present then it runs in full mode, otherwise it runs in demo mode.
The reason for this is A) so that when people purchase the full version the download is close to instant instead of having to wait for the whole app to be downloaded again, and B) so that I don't have to update two market listings whenever I change the code for the app.
So, is it possible to alter the SharedPrefs for a package that is separate from the currently running package?
Android sharedpreferences for an application come in 4 modes.
MODE_PRIVATE is used the most and only internal to the app
MODE_WORLD_READABLE is used if you want your preferences to be
read by another application
MODE_WORLD_WRITEABLE is deprecated API 17 onwards.
MODE_MULTI_PROCESS can be modified by multiple processes.
When an application wants to write preferences,it is called by
Context.getSharedPreferences (String name, int mode).
So it is possible to read the preferences.But to write it that particular app should be using MODE_WORLD_WRITEABLE which is deprecated.
Moral:You cannot alter the preferences of other applications.
And you really should not want to do it either

Is it possible to reliably detect at runtime which store installed an Android App (Google Play or Amazon Market)?

I need to know which store is the App's installer so that I know which store to communicate with for in-App purchase functionality.
Is the definitive 100% reliable approach to generate two separate binaries? Or is there a 100% reliable code-based runtime approach?
There are many similar Stackoverflow questions. All have answers that suggest using methods like getInstallerPackageName on the PackageManager class. All also have comments or conflicting answers saying that this is not a reliable approach, suggesting that the only way to reliably check which store installed a given App is to generate two separate binaries, each with a storeFlag set, and upload one binary to Amazon and one to Google Play.
two binaries would be the most robust method but checking both the Build.MANUFACTURER and the installerName should get you pretty close (though assuming yo want to check for the Amazon AppStore if the user has installed an old version of the installer on their non-Kindle device and not updated the installerName might report null)
boolean isAmazonDevice = Build.MANUFACTURER.equalsIgnoreCase("amazon");
final Application application = getApplication();
String installerName = application.getPackageManager().getInstallerPackageName(application.getPackageName());
boolean fromAmazonStore = installerName != null && installerName.equalsIgnoreCase("com.amazon.venezia");
and then checking the value for:
isAmazonDevice || fromAmazonStore
should get you what you need for a significant amount of the time.
One scenario where this can confuse matters is if you are sideloading your apk for testing - in that case it wouldn't have the correct InstallerPackageName. You can fake that by sideloading the apk using:
adb install -i com.amazon.venezia APK_NAME

How do you back up an android app?

I just had my app crash and now after alot of work its back to were I had it, I was wondering how would I back up the app so I can reInstall is again if this ever happens again?
u should use a version control system, example: git version control
http://git-scm.com/
happy coding!
use a version control system.. like svn or git ... in any case even if you were not using this, you should have taken backup of your code regularly... these version control system manages this for you easily...
This question is not specific to Java or Android, but rather, how to "backup" code properly. As others have already mentioned, you should be using source control systems such as Git or Subversion. Not only will this "backup" your code, it will allow you to track the changes you make to the code as well as maintain multiple versions of your code.

How to take backup for installed packages?

I'm trying to develop an application for taking backup for my device. How can I write this? Till now, I've got all the installed packages list and I'm placing 3 buttons for taking the backup(Backup, CheckAll, Cancel).
If I'm going to take backup button it contains one alertdialog it shows 3 options (now, later, cancel). How to take backup the installed packages to one new list and it'll shows by date and time. How can I do this? Any idea?
i don't know if its possible to do that. I remember that i read in an article that in order to access to other packages you need to use the same user that the app does, and from my point of view that means that all the applications that are going to be backed up need to have the same user. I'm not an android expert but i think it wouldn't be possible to gain access to the other packages if you try Java IO to read the files as you normally do.
Good luck, maybe someone knows how to do this.
I don't know what do you mean by backup installed packages.
Generally users keep backup of their database and preferences data.
If you want to take a backup of your database and preference then you can create xml of your database and preferences using xml-serialization.
More information about xml-serialization Click here
And also you can refer inbuilt facility for get backup Click here

Categories