【问题标题】:DownloadManager notification click intent issueDownloadManager 通知点击意图问题
【发布时间】:2018-03-30 04:56:55
【问题描述】:

我通过应用程序中的 downloadManager 下载内容。当下载完成并且用户点击通知时,我的应用程序打开。

开始下载:

        request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI or DownloadManager.Request.NETWORK_MOBILE)
                .setMimeType(context.getString(R.string.application_mime_type))
                .setTitle(context.getString(R.string.download_title))
                .setDescription(videoName)
                .setDestinationInExternalFilesDir(context,
                        MY_CONTENT_PATH,
                        getFileNameForContent(id, videoName, videoType))
                .setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
        manager.enqueue(request)

捕捉通知点击:

    <activity
        android:name=".presentation.MainActivity"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <data android:mimeType="@string/application_mime_type" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

MainActivity onCreate():

val dataUri = intent.data
    if (dataUri != null) {
        ...
    }

对于 API 19
dataUri = file:///storage/emulated/0/Android/data/ru.mycompany.myapp/files/filename.mp3
对于 API 25
dataUri=content://com.android.providers.downloads.documents/document/276

我的问题:差异取决于 android 版本或设备?我在哪里可以找到这方面的文档?

【问题讨论】:

    标签: android android-intent android-download-manager


    【解决方案1】:

    由于android版本,API 19之后的行为有所不同。 您可以在此处获取更多信息:

    Android: Getting a file URI from a content URI?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-18
      • 1970-01-01
      • 2020-02-02
      • 1970-01-01
      相关资源
      最近更新 更多