Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't crash when system is unable to handle download intent #3108

Merged
merged 1 commit into from Nov 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -3,6 +3,7 @@ package io.homeassistant.companion.android.webview
import android.annotation.SuppressLint
import android.app.DownloadManager
import android.app.PictureInPictureParams
import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
Expand Down Expand Up @@ -1345,8 +1346,15 @@ class WebViewActivity : BaseActivity(), io.homeassistant.companion.android.webvi
}
else -> {
Log.d(TAG, "Received download request for unsupported scheme, forwarding to system")
val browserIntent = Intent(Intent.ACTION_VIEW, uri)
startActivity(browserIntent)
try {
val browserIntent = Intent(Intent.ACTION_VIEW, uri).apply {
flags = Intent.FLAG_ACTIVITY_NEW_TASK
}
startActivity(browserIntent)
} catch (e: ActivityNotFoundException) {
Log.e(TAG, "Unable to forward download request to system", e)
Toast.makeText(this, commonR.string.failed_unsupported, Toast.LENGTH_SHORT).show()
}
}
}
}
Expand Down