I have a BroadcastReceiver
inside a service:
public class NotificationClickService extends Service {
private static final String DEBUG_TAG = "NotificationClickService";
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate() {
registerReceiver(NotificationClickReceiver, new IntentFilter(DownloadManager.ACTION_NOTIFICATION_CLICKED));
}
@Override
public void onDestroy() {
unregisterReceiver(NotificationClickReceiver);
}
BroadcastReceiver NotificationClickReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.d(DEBUG_TAG, "NotificationClickReceiver: onReceive CALLED");
Intent i = new Intent(android.app.DownloadManager.ACTION_VIEW_DOWNLOADS);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_SINGLE_TOP |
Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
context.startActivity(i);
}
};
}
This brings the system Download Manager to the front.
On my phone I'm running CyanogenMod 10.1 based on JellyBean.
But...
As soon as the system app CMupdater starts:
- if CMupdater is currently running, it is called from my service's BroadcastReceiver, instead of the
DownloadManager
; - if CMupdater is not running, but has ran at least once, my receiver is not called at all.
It works again if I reboot and don't run the updater. All tested also on my tablet with the corresponding CyanogenMod 10.1 version.
This is from the CM's receiver:
package com.cyanogenmod.updater.receiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import com.cyanogenmod.updater.UpdatesSettings;
public class NotificationClickReceiver extends BroadcastReceiver{
private static String TAG = "NotificationClickReceiver";
@Override
public void onReceive(Context context, Intent intent) {
// Bring the main app to the foreground
Intent i = new Intent(context, UpdatesSettings.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP |
Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
context.startActivity(i);
}
}
and from its manifest:
<receiver android:name="com.cyanogenmod.updater.receiver.NotificationClickReceiver">
<intent-filter>
<action android:name="android.intent.action.DOWNLOAD_NOTIFICATION_CLICKED"/>
<category android:name="android.intent.category.HOME"/>
</intent-filter>
</receiver>
android.intent.action.DOWNLOAD_NOTIFICATION_CLICKED
is the constant value for the DownloadManager.ACTION_NOTIFICATION_CLICKED
intent I used.