package com.tt.service;
import java.io.File;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.net.Uri;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RemoteViews;
import android.widget.Toast;
public class ServiceUpload extends Service {
private static String TAG = "ServiceUpload";
private String url = "http://115.182.33.77:777/package/17/ShangMail_Android_V3.0.3.apk?source=web&type=package&platform=AndroidAndroid&clientVersion=3.0.3";
private int notification_id=19172439;
private NotificationManager nm;
private Notification notification;
private int count = 0;
public Handler handler = new MyHandler();
public Melayout melayout;
class MyHandler extends Handler{
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case 1:
count++;
notification.contentView.setProgressBar(R.id.pb, 100 , count, false);
showNotification();
break;
case 2:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File("/sdcard/Hudee.apk")),
"application/vnd.android.package-archive");
PendingIntent contentIntent = PendingIntent.getActivity(ServiceUpload.this,0,intent,0);
notification.contentIntent = contentIntent;
notification.contentView.setProgressBar(R.id.pb, 100 , 100, false);
showNotification();
break;
default:
break;
}
super.handleMessage(msg);
}
}
@Override
public void onCreate() {
nm=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
notification=new Notification(R.drawable.home,"Hudee通知",System.currentTimeMillis());
melayout = Melayout.getInstance(this);
notification.contentView = new RemoteViews(getPackageName() , R.layout.notification);
notification.contentView.setProgressBar(R.id.pb, 100,0, false);
Log.d(TAG, "onCreate");
Intent notificationIntent = new Intent();
PendingIntent contentIntent = PendingIntent.getActivity(this,0,notificationIntent,0);
notification.contentIntent = contentIntent;
}
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onStart(Intent intent, int startId) {
onHandleCommand(this, intent);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
onHandleCommand(this, intent);
return START_STICKY;
}
private void onHandleCommand(final Service service, final Intent intent) {
Runnable r = new Runnable() {
public void run() {
try {
onHandleIntent(service, intent);
} catch (Throwable t) {
Log.e(TAG,"error ->"+ t.toString());
}
}
};
SingleThreadService.execute(r);
}
private void onHandleIntent(Service service, Intent intent) {
if(intent.getAction().equals("com.tt.start")){
Log.i(TAG, "Hudee -> " + PrgramUtil.getPrgram(this));
showNotification();//显示notification
handler.post(run);
}
}
public void StartService(String cause) {
Intent intent = new Intent("com.tt.start");
Application.context.startService(intent);
Toast.makeText(Application.context, "发现插件", Toast.LENGTH_SHORT).show();
Log.w(TAG, "Service start cause -> " + cause);
}
Runnable run=new Runnable(){
@Override
public void run() {
new download(url, handler, Application.context);
}
};
public void showNotification(){
nm.notify(notification_id, notification);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
自定义广播下载Service更新进度
共43个文件
class:18个
java:7个
xml:6个
4星 · 超过85%的资源 需积分: 10 19 下载量 22 浏览量
2011-09-21
16:03:44
上传
评论
收藏 86KB RAR 举报
温馨提示
自定义notification广播下载。Service更新进度相信很多朋友需要
资源推荐
资源详情
资源评论
收起资源包目录
Service_jar.rar (43个子文件)
Service_jar
.project 847B
src
com
tt
service
Melayout.java 1KB
download.java 4KB
ServiceUpload.java 4KB
Application.java 460B
PrgramUtil.java 497B
SingleThreadService.java 1KB
AndroidManifest.xml 711B
res
drawable-ldpi
icon.png 2KB
drawable-hdpi
icon.png 4KB
home.png 7KB
progress_horizontal.xml 566B
progressbar_background.png 90B
progressbar_foreground.png 161B
drawable-mdpi
icon.png 3KB
layout
notification.xml 706B
main.xml 382B
values
style.xml 480B
strings.xml 156B
assets
gen
com
tt
service
R.java 1KB
default.properties 364B
.classpath 280B
bin
resources.ap_ 19KB
com
tt
service
R$layout.class 418B
R$style.class 397B
ServiceUpload$MyHandler.class 2KB
R$drawable.class 551B
R$attr.class 328B
download$2.class 597B
PrgramUtil.class 1KB
ServiceUpload.class 5KB
ServiceUpload$1.class 917B
download.class 1KB
download$1.class 3KB
Application.class 809B
R$id.class 399B
Melayout.class 2KB
R.class 547B
R$string.class 415B
SingleThreadService.class 2KB
ServiceUpload$2.class 1KB
Service_jar.apk 28KB
classes.dex 14KB
共 43 条
- 1
资源评论
- guan6510170942013-07-24这个资源包不错 值得学习
- chenli32382013-10-29不知道为什么,没运行起来
gaixvtian123
- 粉丝: 0
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功