I have the following broadcast receiver:
public class UninstallReceiver extends BroadcastReceiver {
@Override
public void onReceive(final Context context, Intent intent) {
String action = intent.getAction();
Log.i("UninstallReceiver", "---------------------> onUNINSTALL():" + action);
DownloadManager dm = (DownloadManager) context.getSystemService(Activity.DOWNLOAD_SERVICE);
VideoDataDAO videosDao = VideoDataDAO.getInstance(context);
final List<VideoData> undownloaded_new_videos = videosDao.getUndownloadedVideosFromDB();
if (undownloaded_new_videos.size() > 0) {
long[] videos = new long[undownloaded_new_videos.size()];
for (int i = 0; i < undownloaded_new_videos.size(); i++) {
videos[i] = undownloaded_new_videos.get(i).getId();
Log.i("UninstallReceiver", "---------------------> onUNINSTALL():" + videos[i]);
}
if (videos != null) {
Log.i("UninstallReceiver", "---------------------> != null: " + Arrays.toString(videos));
dm.remove(videos);
}
}
final List<VideoData> redownloadVideos = videosDao.redownloadVideosFromDB();
if (redownloadVideos.size() > 0) {
long[] videos = new long[redownloadVideos.size()];
for (int i = 0; i < redownloadVideos.size(); i++) {
videos[i] = redownloadVideos.get(i).getId();
Log.i("UninstallReceiver", "---------------------> onUNINSTALL():" + videos[i]);
}
if (videos != null) {
Log.i("UninstallReceiver", "---------------------> != null2");
dm.remove(videos);
}
}
}
}
And it's declared in my manifest like this:
<receiver android:name=".receivers.UninstallReceiver" >
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<action android:name="android.intent.action.PACKAGE_FULLY_REMOVED" />
<data android:scheme="package" />
</intent-filter>
</receiver>
Now my problem is that when I uninstall the application, the broadcast receiver is not called, and then my application keeps downloading videos via the DownloadService. How can I make it recognise my uninstall receiver? Strange enough, if instead of uninstalling, I deploy my app from Eclipse over the one that is already installed (this will uninstall the current app, upload the new apk and install it, this WILL call my uninstall Receiver).