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;
            }
        }
    }
  • 相关阅读:
    diffstat命令
    v-if与v-show的区别
    常数时间插入、删除和获取随机元素
    diff命令
    C++ bitset的简单使用
    树的直径 | 简答的两道模板题
    Codeforces Round #544 (Div. 3)简单题解
    VIM 入门手册, (VS Code)
    PTA 天梯赛 L3-003 社交集群(并查集)
    L3-002 特殊堆栈 (双数组模拟栈)
  • 原文地址:https://www.cnblogs.com/zqxLonely/p/5506066.html
Copyright © 2011-2022 走看看