Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/184.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android通知栏没有';不要改变进程_Java_Android_Android Asynctask_Android Notifications - Fatal编程技术网

Java Android通知栏没有';不要改变进程

Java Android通知栏没有';不要改变进程,java,android,android-asynctask,android-notifications,Java,Android,Android Asynctask,Android Notifications,我正在尝试更新通知栏,因为上传正在进行中。通知将显示,但其进度不会更改,最后当上载完成时,通知将被销毁。通知进度未更改的可能原因 我的代码: ` 类上载文件扩展异步任务{ @凌驾 受保护的字符串doInBackground(文件…参数){ 字符串文件名=参数[0]。getName().replaceAll(“,”); fileName=“gursahib.replaceAll”(“,“”)+”.mp4”; long currentTimeMillis=System.currentTimeMill

我正在尝试更新通知栏,因为上传正在进行中。通知将显示,但其进度不会更改,最后当上载完成时,通知将被销毁。通知进度未更改的可能原因

我的代码:

`

类上载文件扩展异步任务{
@凌驾
受保护的字符串doInBackground(文件…参数){
字符串文件名=参数[0]。getName().replaceAll(“,”);
fileName=“gursahib.replaceAll”(“,“”)+”.mp4”;
long currentTimeMillis=System.currentTimeMillis();
if(上传文件(参数[0],currentTimeMillis+“”+文件名).equals(“200”)){
/*
*如果(postRequest)http://www.phando.com/user/media",
*getMediaRequestParameters(文件名,currentTimeMillis))==
* 200){
* 
*}else{返回“媒体发布失败”。;}
*/
}否则
返回“文件未成功上载。”;
//postRequest(“http://www.phando.com/user/transcoding",
//getTranscodingRequest());
//postRequest(“http://www.phando.com/user/ticket",
//getTicketRequest());
//Log.d(“gursahib”,“done”);
返回文件名;
}
@抑制警告(“弃用”)
私有字符串上传文件(文件文件,字符串文件名){
字符串responseString=null;
HttpClient HttpClient=新的DefaultHttpClient();
HttpPost-HttpPost=newhttppost(Config.FILE\u UPLOAD\u URL);
int statusCode=0;
试一试{
AndroidMultiPartEntity=new AndroidMultiPartEntity(new ProgressListener()){
@凌驾
已转移的公共无效(长数值){
出版进度((int)((num/(float)totalSize)*100);
}
});
File sourceFile=File;
//将文件数据添加到http正文
addPart(“image”,新的文件体(sourceFile,ContentType.DEFAULT_BINARY,fileName));
totalSize=entity.getContentLength();
httppost.setEntity(实体);
//进行服务器呼叫
HttpResponse response=httpclient.execute(httppost);
HttpEntity r_entity=response.getEntity();
statusCode=response.getStatusLine().getStatusCode();
如果(状态代码==200){
responseString=EntityUtils.toString(r_实体);
}否则{
responseString=“出现错误!Http状态代码:”+statusCode;
}
}捕获(客户端协议例外e){
responseString=e.toString();
}捕获(IOE异常){
responseString=e.toString();
}
返回字符串.valueOf(statusCode);
}
private int postRequest(字符串url、列表nameValuePairs){
HttpClient HttpClient=新的DefaultHttpClient();
HttpPost HttpPost=新的HttpPost(url);
试一试{
//添加您的数据
setEntity(新的UrlEncodedFormEntity(nameValuePairs));
//执行HTTP Post请求
HttpResponse response=httpclient.execute(httppost);
返回响应。getStatusLine().getStatusCode();
}捕获(客户端协议例外e){
Log.e(“error”,e.getMessage());
}捕获(IOE异常){
Log.e(“error”,e.getMessage());
}
返回0;
}
@凌驾
受保护的void onPreExecute(){
super.onPreExecute();
}
@凌驾
受保护的void onProgressUpdate(整数…进度){
notificationBuilder.setProgress(100,进度[0],false);
super.onProgressUpdate();
}
@凌驾
受保护的void onPostExecute(字符串结果){
notificationManager.cancel(notificationID);
super.onPostExecute(结果);
}
}
`


控件转到
onProgressUpdate
但通知不会更改

您还需要通知onProgressUpdate异步任务

notificationBuilder.setProgress(100, values[0], false);     
    notificationBuilder.notify(id,notificationBuilder.build());
您需要对生成器调用build()。 之后,通知您的通知经理

Notification notification = 
    notificationBuilder.setProgress(100, progress[0], false).build();
notificationManager.notify(notificationID, notification);
请注意,您还需要为构建器设置图标或其他人员。 此SDK代码可能对您有所帮助

Notification notification = 
    notificationBuilder.setProgress(100, progress[0], false).build();
notificationManager.notify(notificationID, notification);