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;
            }
        }
    }
  • 相关阅读:
    12.10
    4.06Android使用EditText小技巧汇总
    4.05
    4.04Android学习
    4.03Android学习
    4.02Android学习
    4.01Android学习
    3.31构建之法读后感3
    3.30Android学习
    3.29Android学习
  • 原文地址:https://www.cnblogs.com/zqxLonely/p/5506066.html
Copyright © 2011-2022 走看看