123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- package me.yoqi.mobile.tool;
- import android.annotation.TargetApi;
- import android.app.Notification;
- import android.app.NotificationManager;
- import android.app.PendingIntent;
- import android.app.Service;
- import android.content.Intent;
- import android.os.Build;
- import android.os.IBinder;
- import me.yoqi.mobile.safe.MainActivity;
- import me.yoqi.mobile.safe.R;
- public class ServiceTool extends Service {
- private NotificationManager mNF;
- public static String AUTO_START = "com.ldci.android.t56.mobile.safe.AUTO_START";
- @Override
- public IBinder onBind(Intent arg0) {
- return null;
- }
- @Override
- public void onCreate() {
- super.onCreate();
- }
- // public static int serviceInt = 0;
- @Override
- public void onStart(Intent intent, int startId) {
- super.onStart(intent, startId);
- // Toast.makeText(this, "开启服务,发出通知", Toast.LENGTH_LONG).show();
- // new Thread(new Runnable(){
- // public void run(){
- // while(true){
- // try {
- // Thread.sleep(1000);
- // serviceInt = 0;
- // } catch (InterruptedException e) {
- // e.printStackTrace();
- // }
- // }
- // }
- // }).start();
- autoStartNotification();
- }
- @Override
- public void onDestroy() {
- super.onDestroy();
- // Toast.makeText(this, "停止服务,取消通知", Toast.LENGTH_LONG).show();
- mNF.cancel(R.string.app_name);
- }
- @TargetApi(Build.VERSION_CODES.HONEYCOMB)
- private void autoStartNotification() {
- Notification mNotification = new Notification(R.drawable.app_logo, "365手机秘书", System.currentTimeMillis());
- Intent intent = new Intent(this, MainActivity.class);
- intent.setAction(AUTO_START);
- intent.putExtra("auto_start", "boot_completed");
- PendingIntent mPI = PendingIntent.getActivity(this, 0, intent, 0);
- // mNotification.setLatestEventInfo(this, "365手机秘书", "成功开机启动", mPI);
- // Notification.Builder builder = new Notification.Builder(MainActivity.this);
- // builder.setAutoCancel(true);
- if (null == mNF) {
- mNF = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
- }
- mNF.notify(R.string.app_name, mNotification);
- }
- }
|