0

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).

4

1 回答 1

0

我把这个:

 <uses-permission android:name="android.permission.BROADCAST_PACKAGE_REMOVED" />

但后来我不得不更改 lint 设置,以将其声明为警告而不是错误的方式,以便我可以构建应用程序。

于 2013-08-09T11:45:27.423 回答