Is there on install event in android?
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();
Event when application gets installed (Android)
No you can't, the user has to explicitly start your application.
You can always check for the first time your application is launched.
Receiving package install and uninstall events
I tried to register the BroadcastReceiver
in either manifest file or java code. But both of these two methods failed to trigger the onReceive()
method.
After googling this problem, I found a solution for both methods from another Thread in SO:
Android Notification App
In the manifest file (this approach no longer applies since API 26 (Android 8), it was causing performance issues on earlier Android versions):
<receiver android:name=".YourReceiver">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_INSTALL" />
<action android:name="android.intent.action.PACKAGE_ADDED" />
<data android:scheme="package"/>
</intent-filter>
</receiver>
In java code:
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
intentFilter.addAction(Intent.ACTION_PACKAGE_INSTALL);
intentFilter.addDataScheme("package");
registerReceiver(br, intentFilter);
This should work for you.
Android application install/uninstall event
Maybe someone will be interested. I found the code that allows me to checked system reboot after installation/update:
public static boolean phone_rebooted(Context ctx) {
ApplicationInfo appInfo = ctx.getApplicationInfo();
String appFile = appInfo.sourceDir;
long installed = new File(appFile).lastModified();
long boot_time = System.currentTimeMillis() - SystemClock.elapsedRealtime();
if(boot_time < installed) {
return false;
} else {
return true;
}
}
Android - catch the Cancel event when installing an .apk programmatically
You can add another Receiver to listen for the installed package
<receiver android:name=".ApkInstalledReceiver" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED" />
<data android:scheme="package" />
</intent-filter>
</receiver>
so, if the user cancels the installation you won't receive it.
Related Topics
The Activity Must Be Exported or Contain an Intent-Filter
What Is the Simplest Way to Reverse an Arraylist
Firebase Database Points to Wrong Database Url
Android: Why Setvisibility(View.Gone); or Setvisibility(View.Invisible); Do Not Work
What Is the Correct Way to Do Inserts/Updates/Deletes in Android SQLitedatabase Using a Query String
Fixing 'Path' in Environment Variables in Windows 7 for Multiple Applications
How Does the Fetchmode Work in Spring Data JPA
Java Hotspot(Tm) 64-Bit Server Vm Warning: Ignoring Option Maxpermsize
How to Get String Response from Retrofit2
How to Activate "Share" Button in Android App
Onrequestpermissionsresult Not Being Called in Dialog Fragment