I have been following this question but with no success, basically, I want to get notified when something is downloaded or put into Downloads folder from whatever source, e.g. downloading, putting it there by computer. The problem is, I am not receiving any response from my receiver. Here is my code:
public class DownloadReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.d("TAG", "SOMETHING DOWNLOADED");
Toast.makeText(context, "SOMETHING DOWNLOADED", Toast.LENGTH_SHORT).show();
long receivedID = intent.getLongExtra(
DownloadManager.EXTRA_DOWNLOAD_ID, -1L);
DownloadManager mgr = (DownloadManager)
context.getSystemService(Context.DOWNLOAD_SERVICE);
DownloadManager.Query query = new DownloadManager.Query();
query.setFilterById(receivedID);
Cursor cur = mgr.query(query);
int index = cur.getColumnIndex(DownloadManager.COLUMN_STATUS);
if(cur.moveToFirst()) {
if(cur.getInt(index) == DownloadManager.STATUS_SUCCESSFUL){
// do something
Log.d("TAG", "SOMETHING DOWNLOADED");
Toast.makeText(context, "SOMETHING DOWNLOADED", Toast.LENGTH_SHORT).show();
}
}
cur.close();
}
this is how I register it in my Application file:
final IntentFilter downloadFilter = new IntentFilter();
downloadFilter.addAction("android.intent.action.DOWNLOAD_COMPLETE");
registerReceiver(new DownloadReceiver(),downloadFilter);
and this is my Android manifest:
<receiver android:name="com.tproductions.Openit.provider.DownloadReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.DOWNLOAD_COMPLETE" android:enabled="true" />
</intent-filter>
</receiver>