小编khc*_*tro的帖子

使用DownloadManager显示在活动中下载进度

我正在尝试重现DownloadManager在我的应用程序内的通知栏中显示的相同进度,但我的进度永远不会发布.我正在尝试使用runOnUiThread()更新它,但由于某种原因它没有更新.

我的下载:

String urlDownload = "https://dl.dropbox.com/s/ex4clsfmiu142dy/test.zip?token_hash=AAGD-XcBL8C3flflkmxjbzdr7_2W_i6CZ_3rM5zQpUCYaw&dl=1";
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(urlDownload));

request.setDescription("Testando");
request.setTitle("Download");
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "teste.zip");

final DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);

final long downloadId = manager.enqueue(request);

final ProgressBar mProgressBar = (ProgressBar) findViewById(R.id.progressBar1);

new Thread(new Runnable() {

    @Override
    public void run() {

        boolean downloading = true;

        while (downloading) {

            DownloadManager.Query q = new DownloadManager.Query();
            q.setFilterById(downloadId);

            Cursor cursor = manager.query(q);
            cursor.moveToFirst();
            int bytes_downloaded = cursor.getInt(cursor
                    .getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR));
            int bytes_total = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES));

            if (cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS)) == DownloadManager.STATUS_SUCCESSFUL) {
                downloading = false;
            }

            final …
Run Code Online (Sandbox Code Playgroud)

android progress-bar

87
推荐指数
3
解决办法
4万
查看次数

吐司未显示在Android Q中

ToastAndroid Q中不起作用。有什么变化Toast吗?我找不到的发行说明Toast
我的代码很简单。

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    Toast.makeText(this, "onCreate", Toast.LENGTH_SHORT).show()
}

fun onButtonClick(view: View) {
    Toast.makeText(this, "onButtonClick", Toast.LENGTH_SHORT).show()
}
Run Code Online (Sandbox Code Playgroud)

这正常工作与Android的馅饼,但与Android Q.没有运气
发生了什么事Toast

android toast android-10.0

7
推荐指数
1
解决办法
484
查看次数

WKWebView 初始化后 addUserScript 不起作用

当我WKUserContentControllerWKWebView创建实例后更改时。这是我的代码。

let configuration = WKWebViewConfiguration()
let userController = WKUserContentController()
userController.addUserScript(WKUserScript(source: "alert('it works')", injectionTime: .atDocumentEnd, forMainFrameOnly: true))

configuration.userContentController = userController // before instantiate WKWebView

webView = WKWebView(frame: view.frame, configuration: configuration)
webView.navigationDelegate = self
webView.uiDelegate = self

view = webView
Run Code Online (Sandbox Code Playgroud)

上面的代码工作正常,但下面不是

let configuration = WKWebViewConfiguration()
let userController = WKUserContentController()
userController.addUserScript(WKUserScript(source: "alert('it doesn't work')", injectionTime: .atDocumentEnd, forMainFrameOnly: true))

webView = WKWebView(frame: view.frame, configuration: configuration)
webView.navigationDelegate = self
webView.uiDelegate = self

webView.configuration.userContentController = userController // 
// neither configuration.userContentController = userController …
Run Code Online (Sandbox Code Playgroud)

ios wkwebview

3
推荐指数
1
解决办法
1303
查看次数

标签 统计

android ×2

android-10.0 ×1

ios ×1

progress-bar ×1

toast ×1

wkwebview ×1