gpt4 book ai didi

java - Android - 从BroadcastReceiver获取标题和描述

转载 作者:行者123 更新时间:2023-12-01 13:38:29 25 4
gpt4 key购买 nike

我正在开发一个 Android 应用程序。

我使用 BroadcastReciever 来让人们知道下载完成的位置。

        DownloadManager.Request request = new DownloadManager.Request(Uri.parse(urlString));
request.setDescription(artistString);
request.setTitle(titleString);
// in order for this if to run, you must use the android 3.2 to compile your app
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
}
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_MUSIC + "/Tunesto", titleString + " - " + artistString + ".mp3");

Toast.makeText(mainContext, "Downloading " + titleString + " - " + artistString, Toast.LENGTH_SHORT).show();

// get download service and enqueue file
DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request);

然后我在 onCreate 方法中使用它来在下载结束时显示 toast:

onComplete = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
String info = "";
info = info + " - " + intent.getStringExtra(DownloadManager.COLUMN_DESCRIPTION);
info = info + " - " + intent.getStringExtra(DownloadManager.COLUMN_TITLE);
info = info + " - " + intent.getStringExtra(DownloadManager.COLUMN_ID);
info = info + " - " + intent.getStringExtra(DownloadManager.COLUMN_LOCAL_FILENAME);
info = info + " - " + intent.getStringExtra(DownloadManager.COLUMN_MEDIA_TYPE);
info = info + " - " + intent.getStringExtra(DownloadManager.COLUMN_TOTAL_SIZE_BYTES);
info = info + " - " + intent.getDataString();
info = info + " - " + intent.getType();
info = info + " - " + intent.EXTRA_TITLE;
info = info + " - " + intent.EXTRA_TEXT;

//Toast.makeText(mainContext, Integer.valueOf(dlCount) + " Download \"" + titleString + " - " + artistString + "\" completed", Toast.LENGTH_LONG).show();
Toast.makeText(mainContext, info + "Download completed", Toast.LENGTH_LONG).show();
}
};

registerReceiver(onComplete, new IntentFilter(
DownloadManager.ACTION_DOWNLOAD_COMPLETE));

正如你所看到的,我已经尝试了一切来获取信息字符串中的描述和标题,但它不会显示除 null 之外的任何内容(tHE toast 显示类似...的内容

您能给我一些如何检索这些信息的提示吗?

最佳答案

Can you please give me a tips on how to retrieve those informations?

读入值for EXTRA_DOWNLOAD_ID ,通过在广播 Intent 上调用 getLongExtra()。然后,将其与 DownloadManager.Query 结合使用来检索此下载的数据。在 DownloadManager 上调用 query() 返回的 Cursor 将包含由 COLUMN_ 常量键入的值。

This blog post有示例代码说明了此过程。

关于java - Android - 从BroadcastReceiver获取标题和描述,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21052299/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com