com.multimediacall.R.layout.downloadnotification布局内的 R.id.tv_down R.id.pb_schedule 在 handler 调用notificationManager.notify(R.drawable.download_downloading, notification);时找不到 View
package com.multimediacall.download;import java.io.File;import com.multimediacall.R;
import com.multimediacall.download.stream.DownloadProgressListener;
import com.multimediacall.download.stream.FileDownload;
import com.multimediacall.util.SysParam;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.provider.MediaStore.Audio;
import android.util.Log;
import android.widget.RemoteViews;public class DownloadService extends android.app.Service{
private static final String TAG = "DownloadService";
private FileDownload fileDownload;
private NotificationManager notificationManager;
private Notification notification;
private int count = 0;
private StringBuffer sb;
private File dir;
public void onCreate() {
notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
notification = new Notification(R.drawable.download_downloading,"收到共享文件",System.currentTimeMillis());
notification.contentView = new RemoteViews(getPackageName(),com.multimediacall.R.layout.downloadnotification);
// notification.contentView.setProgressBar(R.id.pb_schedule, 100,0, false);
notification.contentView.setTextViewText(R.id.tv_down,"0 ");
//设置进度条,最大值 为100,当前值为0,最后一个参数为true时显示条纹
//(就是在Android Market下载软件,点击下载但还没获取到目标大小时的状态)
Intent notificationIntent = new Intent(this,DownloadService.class);
PendingIntent contentIntent = PendingIntent.getActivity(this,0,notificationIntent,0);
notification.contentIntent = contentIntent;
notification.setLatestEventInfo(this, "任务标题", "任务内容", contentIntent);
notification.sound = Uri.parse("android.resource://com.multimediacall/raw/message"); notificationManager.notify(R.drawable.download_downloading, notification);
//
// System.out.println(" onCreate ");
}
public void onStart(Intent intent, int startId)
{
super.onStart(intent, startId);
System.out.println(" onStart ");
Bundle bundle = intent.getExtras();
String phoneNumber = (String)bundle.getString("phoneNumber");
System.out.println("phoneNumber" + phoneNumber);
sb = new StringBuffer(SysParam.server);
sb.append(SysParam.downloadServlet);
sb.append("1=" + phoneNumber);
sb.append("&2=320" );
sb.append("&3=480");
sb.append("&4=0");
sb.append("&5=0");
if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
{
dir = Environment.getExternalStorageDirectory();//文件保存目录
if(dir.exists())
{
print(sb.toString());
new Thread(new Runnable(){
public void run() {
fileDownload = new FileDownload(DownloadService.this, sb.toString(), dir);
if(fileDownload.getMessageFlag().equals("OK!DM"))
{
int length = fileDownload.getFileSize();//获取文件的长度
try{
fileDownload.download(new DownloadProgressListener(){
public void onDownloadSize(int size) {//可以实时得到文件下载的长度
Message message = new Message();
Bundle bundle = new Bundle();
bundle.putInt("size", size);
message.setData(bundle);
handler.sendMessage(message);
}});
System.out.println("file download over ...........");
notificationManager.cancel(R.drawable.download_downloading); System.out.println("over ...............");
}
catch(Exception e){
print(e.toString());
e.printStackTrace();
}
}
else if(fileDownload.getMessageFlag().equals("NO!DM"))
{
// Message msg = new Message();//信息提示
// msg.what = -1;
// msg.getData().putString("error", "无文件下载");//
// handler.sendMessage(msg);
return ;
}
else if(fileDownload.getMessageFlag().equals("ER!DM"))
{
// Message msg = new Message();//信息提示
// msg.what = -1;
// msg.getData().putString("error", "文件下载失败");//
// handler.sendMessage(msg);
return ;
}
System.out.println("over ...................");
}
}).start();
}
}
else
{
this.onDestroy();
}
}
private Handler handler = new Handler(){
public void handleMessage(Message msg) {
super.handleMessage(msg);
Bundle bundle = msg.getData();
int size = bundle.getInt("size");
System.out.println(" 1 ");
notification.contentView.setTextViewText(com.multimediacall.R.id.tv_down," "+ size);// notification.contentView.setProgressBar(R.id.pb_schedule, fileDownload.getFileSize(),size, false);
System.out.println(" 2 ");
notificationManager.notify(R.drawable.download_downloading, notification);
System.out.println(" 3 ");
}
};
public void onDestroy() {
super.onDestroy();
System.out.println(" onDestroy ");
}
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
System.out.println(" onBind ");
return null;
} public boolean onUnbind(Intent intent) {
System.out.println(" onUnbind ");
return super.onUnbind(intent);
} //打印日志
private static void print(String msg){
Log.i(TAG, msg);
}}
大家帮忙看下
package com.multimediacall.download;import java.io.File;import com.multimediacall.R;
import com.multimediacall.download.stream.DownloadProgressListener;
import com.multimediacall.download.stream.FileDownload;
import com.multimediacall.util.SysParam;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.provider.MediaStore.Audio;
import android.util.Log;
import android.widget.RemoteViews;public class DownloadService extends android.app.Service{
private static final String TAG = "DownloadService";
private FileDownload fileDownload;
private NotificationManager notificationManager;
private Notification notification;
private int count = 0;
private StringBuffer sb;
private File dir;
public void onCreate() {
notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
notification = new Notification(R.drawable.download_downloading,"收到共享文件",System.currentTimeMillis());
notification.contentView = new RemoteViews(getPackageName(),com.multimediacall.R.layout.downloadnotification);
// notification.contentView.setProgressBar(R.id.pb_schedule, 100,0, false);
notification.contentView.setTextViewText(R.id.tv_down,"0 ");
//设置进度条,最大值 为100,当前值为0,最后一个参数为true时显示条纹
//(就是在Android Market下载软件,点击下载但还没获取到目标大小时的状态)
Intent notificationIntent = new Intent(this,DownloadService.class);
PendingIntent contentIntent = PendingIntent.getActivity(this,0,notificationIntent,0);
notification.contentIntent = contentIntent;
notification.setLatestEventInfo(this, "任务标题", "任务内容", contentIntent);
notification.sound = Uri.parse("android.resource://com.multimediacall/raw/message"); notificationManager.notify(R.drawable.download_downloading, notification);
//
// System.out.println(" onCreate ");
}
public void onStart(Intent intent, int startId)
{
super.onStart(intent, startId);
System.out.println(" onStart ");
Bundle bundle = intent.getExtras();
String phoneNumber = (String)bundle.getString("phoneNumber");
System.out.println("phoneNumber" + phoneNumber);
sb = new StringBuffer(SysParam.server);
sb.append(SysParam.downloadServlet);
sb.append("1=" + phoneNumber);
sb.append("&2=320" );
sb.append("&3=480");
sb.append("&4=0");
sb.append("&5=0");
if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
{
dir = Environment.getExternalStorageDirectory();//文件保存目录
if(dir.exists())
{
print(sb.toString());
new Thread(new Runnable(){
public void run() {
fileDownload = new FileDownload(DownloadService.this, sb.toString(), dir);
if(fileDownload.getMessageFlag().equals("OK!DM"))
{
int length = fileDownload.getFileSize();//获取文件的长度
try{
fileDownload.download(new DownloadProgressListener(){
public void onDownloadSize(int size) {//可以实时得到文件下载的长度
Message message = new Message();
Bundle bundle = new Bundle();
bundle.putInt("size", size);
message.setData(bundle);
handler.sendMessage(message);
}});
System.out.println("file download over ...........");
notificationManager.cancel(R.drawable.download_downloading); System.out.println("over ...............");
}
catch(Exception e){
print(e.toString());
e.printStackTrace();
}
}
else if(fileDownload.getMessageFlag().equals("NO!DM"))
{
// Message msg = new Message();//信息提示
// msg.what = -1;
// msg.getData().putString("error", "无文件下载");//
// handler.sendMessage(msg);
return ;
}
else if(fileDownload.getMessageFlag().equals("ER!DM"))
{
// Message msg = new Message();//信息提示
// msg.what = -1;
// msg.getData().putString("error", "文件下载失败");//
// handler.sendMessage(msg);
return ;
}
System.out.println("over ...................");
}
}).start();
}
}
else
{
this.onDestroy();
}
}
private Handler handler = new Handler(){
public void handleMessage(Message msg) {
super.handleMessage(msg);
Bundle bundle = msg.getData();
int size = bundle.getInt("size");
System.out.println(" 1 ");
notification.contentView.setTextViewText(com.multimediacall.R.id.tv_down," "+ size);// notification.contentView.setProgressBar(R.id.pb_schedule, fileDownload.getFileSize(),size, false);
System.out.println(" 2 ");
notificationManager.notify(R.drawable.download_downloading, notification);
System.out.println(" 3 ");
}
};
public void onDestroy() {
super.onDestroy();
System.out.println(" onDestroy ");
}
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
System.out.println(" onBind ");
return null;
} public boolean onUnbind(Intent intent) {
System.out.println(" onUnbind ");
return super.onUnbind(intent);
} //打印日志
private static void print(String msg){
Log.i(TAG, msg);
}}
大家帮忙看下
解决方案 »
- 关于android中线程被系统停止的问题 !!!
- 求助:在短信的数据库里添加一条短信未读,怎么实现推送?
- 100分------------求java算法 如何在字节流中是否含有指定的四个字节呢
- android 模拟器无法上网
- 切换主题,通过apk格式,为什么textview的背景颜色和字体颜色问题
- 语法救助
- android屏幕适配问题
- 高分跪求在游戏类 (SurfaceView) 里切入 admob广告用例(100分)
- Android按照教科书编写的代码出错,求解
- 游戏中大量的图片,导致崩溃
- LBS是怎样开发的?
- 求助android..CursorIndexOutOfBoundsException: Index 0 requested,with a size of 0
把这句删除就行了. 具体什么问题. 我现在也不知道 ... 邪恶