Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get action that android application is trying removed/uninstalled from device
    text
    copied!<p>When user want to uninstall app from android device, I want user uninstall button click event for that application.</p> <p>I am getting event of application is removed from device, but I want to show pop-up before application is removed. I am trying to achieve same like doing in 'App Lock' application.</p> <p>Here is my code to get application removed event through broadcast receiver. But I am totally blank about uninstall button click or before pop-up click. Please guide me in right direction.</p> <p>Thanks in advance.</p> <pre><code>public class MainActivity extends Activity { CustomBroadcastReceiver mApplicationsReceiver; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mApplicationsReceiver=new CustomBroadcastReceiver(); IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED); filter.addAction(Intent.ACTION_PACKAGE_REMOVED); filter.addAction(Intent.ACTION_PACKAGE_CHANGED); filter.addAction(Intent.ACTION_PACKAGE_ADDED); filter.addAction(Intent.ACTION_PACKAGE_REPLACED); filter.addAction(Intent.ACTION_PACKAGE_RESTARTED); filter.addAction(Intent.ACTION_PACKAGE_VERIFIED); filter.addAction(Intent.ACTION_PACKAGE_INSTALL); filter.addAction(Intent.ACTION_PACKAGE_FIRST_LAUNCH); filter.addAction(Intent.ACTION_DELETE); filter.addAction(Intent.ACTION_DEFAULT); filter.addDataScheme("package"); registerReceiver(mApplicationsReceiver, filter); } } public class CustomBroadcastReceiver extends BroadcastReceiver { /** * This method captures the event when a package has been removed */ @Override public void onReceive(Context context, Intent intent) { System.out.println("Hello from CustomBroadcastReceiver"); if (intent != null) { String action = intent.getAction(); System.out.println("L1123 : "+action); if (action.equals(intent.ACTION_PACKAGE_REMOVED)) { //Log the event capture in the log file ... System.out.println("The package has been removed"); } } } } &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.bits.uninstallappdemo" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /&gt; &lt;uses-permission android:name="android.permission.BROADCAST_PACKAGE_REMOVED" /&gt; &lt;uses-permission android:name="android.permission.INSTALL_PACKAGES" /&gt; &lt;uses-permission android:name="android.permission.DELETE_PACKAGES" /&gt; &lt;uses-permission android:name="android.permission.BROADCAST_PACKAGE_ADDED" /&gt; &lt;uses-permission android:name="android.permission.BROADCAST_PACKAGE_CHANGED" /&gt; &lt;uses-permission android:name="android.permission.BROADCAST_PACKAGE_INSTALL" /&gt; &lt;uses-permission android:name="android.permission.BROADCAST_PACKAGE_REPLACED" /&gt; &lt;application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" &gt; &lt;activity android:name=".MainActivity" android:label="@string/app_name" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;!-- &lt;receiver android:name=".CustomBroadcastReceiver" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.PACKAGE_REMOVED" /&gt; &lt;action android:name="android.intent.action.PACKAGE_ADDED" /&gt; &lt;category android:name="android.intent.category.DEFAULT" /&gt; &lt;action android:name="android.intent.action.PACKAGE_ADDED" /&gt; &lt;action android:name="android.intent.action.PACKAGE_CHANGED" /&gt; &lt;action android:name="android.intent.action.PACKAGE_INSTALL" /&gt; &lt;action android:name="android.intent.action.PACKAGE_REMOVED" /&gt; &lt;action android:name="android.intent.action.PACKAGE_REPLACED" /&gt; &lt;/intent-filter&gt; &lt;/receiver&gt; --&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload