When a user wants to remove an application from an Android device, I want the user to delete the button click event for this application.
I get an application event deleted from the device, but I want to show a popup before uninstalling the application. I am trying to achieve the same as in the App Lock application.
Here is my code to receive a remote application event through a broadcast receiver. But I'm completely empty about clicking the delete button or before the pop-up click. Please guide me in the right direction.
Thanks in advance.
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"); } } } } <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.bits.uninstallappdemo" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /> <uses-permission android:name="android.permission.BROADCAST_PACKAGE_REMOVED" /> <uses-permission android:name="android.permission.INSTALL_PACKAGES" /> <uses-permission android:name="android.permission.DELETE_PACKAGES" /> <uses-permission android:name="android.permission.BROADCAST_PACKAGE_ADDED" /> <uses-permission android:name="android.permission.BROADCAST_PACKAGE_CHANGED" /> <uses-permission android:name="android.permission.BROADCAST_PACKAGE_INSTALL" /> <uses-permission android:name="android.permission.BROADCAST_PACKAGE_REPLACED" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
source share