我正在尝试重现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) Toast在Android 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?
当我WKUserContentController在WKWebView创建实例后更改时。这是我的代码。
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)