I have a problem trying to handle notification click events for downloaded .mp3 files. I already registered the following:
The problem is, when I click on a completed download, I get a list of apps that can handle that download .mp3 file (like VLC).
Is there a way to restrict the notification item click so that it's only handled by my app? By the way, my app doesn't even show in the list.
P.S. Would be nice if the solution didn't involve having to create my custom notification handling.
Edit 1: Here's the code to start the download:
private void downloadRequest(int position, String url, String title, String description, String filename) {
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setDescription(description);
request.setTitle(title);
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
try {
request.setDestinationUri(Uri.fromFile(new File(FileUtils.getAudioDirectory(getActivity()) + filename)));
} catch (IOException e) {
e.printStackTrace();
}
enqueue = mDownloadManager.enqueue(request);
As per matty357's request, here's my broadcast receiver for the notification click:
private BroadcastReceiver receiverNotificationClicked = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String extraId = DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS;
long[] references = intent.getLongArrayExtra(extraId);
for(long reference : references) {
AppLog.d("DOWNLOAD_MANAGER", "reference (clicked): " + reference);
}
AppLog.d("DOWNLOAD_MANAGER", "Received click");
}
};
The solution for this is to put:
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE);
So you won't have a notification when download is finished. And:
context.registerReceiver(onComplete,
new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
So you will be able to put a notification when download is completed.
BroadcastReceiver onComplete=new BroadcastReceiver() {
public void onReceive(Context ctxt, Intent intent) {
Log.d(TAG,"onComplete");
// AND HERE SET YOUR ONW NOTIFICATION WHICH YOU WILL ABLE TO HANDLE
}
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With