zoukankan      html  css  js  c++  java
  • 前台服务

    package com.pingyijinren.test;
    
    import android.annotation.TargetApi;
    import android.app.Notification;
    import android.app.PendingIntent;
    import android.app.Service;
    import android.content.Intent;
    import android.os.Binder;
    import android.os.Build;
    import android.os.IBinder;
    import android.util.Log;
    
    public class MyService extends Service {
        private DownloadBinder downloadBinder=new DownloadBinder();
        public MyService() {
        }
    
        @Override
        public IBinder onBind(Intent intent) {
            // TODO: Return the communication channel to the service.
            //throw new UnsupportedOperationException("Not yet implemented");
            return downloadBinder;
        }
    
        @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
        @Override
        public void onCreate(){
            super.onCreate();
            Log.d("MainActivity","create");
    
            Notification.Builder notificationBuilder=new Notification.Builder(this);
            notificationBuilder.setContentTitle("叶良辰")
                    .setContentText("我有一百种方法让你呆不下去")
                    .setTicker("收到叶良辰的消息")
                    .setWhen(System.currentTimeMillis())
                    .setSmallIcon(R.mipmap.ic_launcher);
            Notification notification=notificationBuilder.build();
            startForeground(1,notification);
    
        }
    
        @Override
        public int onStartCommand(Intent intent,int flags,int startId){
            Log.d("MainActivity","startCommand");
            return super.onStartCommand(intent,flags,startId);
        }
    
        @Override
        public void onDestroy(){
            super.onDestroy();
            Log.d("MainActivity","destroy");
        }
    
        class DownloadBinder extends Binder {
            public void startDownload(){
                Log.d("MainActivity","startDownload");
            }
    
            public int getProgress(){
                Log.d("MainActivity","getProgress");
                return 0;
            }
        }
    }
  • 相关阅读:
    oracle查看被锁的表和被锁的进程,杀掉进程
    umlの交互图
    Window XP安装Ubuntu14.04实现Samba文件共享
    开源企业IM免费企业即时通讯ENTBOOST V2014.177版本号正式公布
    必看的 jQuery性能优化的38个建议
    正则工具类以及FinalClass
    CF772E Verifying Kingdom
    aop相关术语
    BeanFactoryAware和BeanNameAware
    spring完成自动装配
  • 原文地址:https://www.cnblogs.com/zqxLonely/p/5506066.html
Copyright © 2011-2022 走看看