gpt4 book ai didi

android - 刷新通知栏中的进度条

转载 作者:IT王子 更新时间:2023-10-28 23:31:26 26 4
gpt4 key购买 nike

我想在通知栏中放置一个进度条。这个想法是在程序将文件上传到服务器时显示进度条。其他一切都很好,但我不知道如何刷新通知内的进度条。有人知道可以玩什么模式吗?我的意思是,我应该在哪里刷新进度条,在服务或 Activity 中等等。

最佳答案

我不知道你的代码是什么样的,所以我不知道你需要修改什么,但是我通过文档进行了一些搜索。我在 Notifications 上找到了一些东西, ProgressBars , 和 RemoteViews .

具体来说,在 RemoveView 中,您可以更新进度条。因此,结合每个链接中的一些示例代码,我得到如下内容:

public class MyActivity extends Activity {
private static final int PROGRESS = 0x1;
private static final int MAX_PROGRESS = 100;

private int mProgressStatus = 0;

private Handler mHandler = new Handler();

protected void onCreate(Bundle icicle) {
super.onCreate(icicle);

//define Notification
//...

RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification_layout);
contentView.setProgressBar(R.id.progress_bar, MAX_PROGRESS, mProgressStatus, false);
notification.contentView = contentView;

// Start file upload in a background thread
new Thread(new Runnable() {
public void run() {
while (mProgressStatus < MAX_PROGRESS) {
mProgressStatus = doWork();

// Update the progress bar
mHandler.post(new Runnable() {
public void run() {
contentView.setProgressBar(R.id.progress_bar, MAX_PROGRESS, mProgressStatus, false);
}
});
}
}
}).start();
}
}

关于android - 刷新通知栏中的进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2689729/

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