1 package com.szy.status;
2
3 import android.app.IntentService;
4 import android.app.Notification;
5 import android.app.NotificationManager;
6 import android.app.PendingIntent;
7 import android.content.Intent;
8 import android.util.Log;
9
10 /**
11 * @author coolszy
12 * @blog http://blog.csdn.net/coolszy
13 */
14 public class StatusService extends IntentService
15 {
16 private static final String TAG = "StatusService";
17
18 // private static final int KUKA = 0;
19
20 public StatusService()
21 {
22 super("StatusService");
23 }
24
25 @Override
26 protected void onHandleIntent(Intent intent)
27 {
28 Log.i(TAG, "开始下载....");
29 showNotification(false);
30 try
31 {
32 Thread.sleep(10000);
33 showNotification(true);
34 } catch (InterruptedException e)
35 {
36 e.printStackTrace();
37 }
38 Log.i(TAG, "程序下载完毕");
39 }
40
41 private void showNotification(boolean finish)
42 {
43 Notification notification;
44 NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
45 Intent intent = new Intent(this, MainActivity.class);
46 PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
47 if (!finish)
48 {
49 notification = new Notification(R.drawable.head, "开始下载", System.currentTimeMillis());
50 notification.setLatestEventInfo(this, "下载", "正在下载中", contentIntent);
51 }
52 else
53 {
54 notification = new Notification(R.drawable.head, "下载完毕", System.currentTimeMillis());
55 notification.setLatestEventInfo(this, "下载", "程序下载完毕", contentIntent);
56 }
57 notification.defaults=Notification.DEFAULT_ALL;
58 manager.notify(R.layout.main, notification);
59
60 }
61
62 }