zoukankan      html  css  js  c++  java
  • android------锁屏(手机启动出现锁屏界面)

    以前用过一个红包锁屏的软件,第一次打开手机出现锁屏,滑动领取收益,当时觉得这功能不错,就查阅资料,写了一个案例,

    apk运行流程: 进入软件---》启动服务---》关闭手机(可先退出应用)--》再打开手机即可看见锁屏界面

    效果图:

                    

    当然这个案例还是有缺点的,没考虑性能问题。

    界面是可以随意修改的,滑动的是一个自定义控件。

    服务类

    public class AppService extends Service {
    
        private AppReceiver mLockScreenReceiver;
        
        private IntentFilter mIntentFilter = new IntentFilter();
        @Override
        public IBinder onBind(Intent intent) {
            // TODO Auto-generated method stub
            return null;
        }
        
        @Override
        public int onStartCommand(Intent intent, int flags, int startId) {
            // 监听屏幕关闭和打开的广播必须动态注册
            mIntentFilter.addAction(Intent.ACTION_BOOT_COMPLETED);
            mIntentFilter.addAction(Intent.ACTION_SCREEN_OFF);
            mIntentFilter.addAction(Intent.ACTION_SCREEN_ON);
            mIntentFilter.addAction(Intent.ACTION_TIME_TICK);
            // 设置广播的优先级
            mIntentFilter.setPriority(Integer.MAX_VALUE);
            if (null == mLockScreenReceiver) {
                mLockScreenReceiver = new AppReceiver();
                mIntentFilter.setPriority(Integer.MAX_VALUE);
                registerReceiver(mLockScreenReceiver, mIntentFilter);
                Toast.makeText(getApplicationContext(), "AppService", Toast.LENGTH_LONG).show();
                
                
            }
            NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
            builder.setTicker("APP正在运行");
            builder.setAutoCancel(false);
            builder.setContentTitle("APP正在运行");
            builder.setContentText("您的收益正在累积");
            builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher));
            builder.setSmallIcon(R.mipmap.ic_launcher);
            builder.setContentIntent(PendingIntent.getActivity(this, 0, new Intent(this, LockScreenActivity.class), PendingIntent.FLAG_UPDATE_CURRENT));
            Notification n = builder.build();
            // 通知栏显示系统图标
            startForeground(0x111, n);
            
            Parser.killBackgroundProcess(this);
            return START_STICKY;
        }
        
        @Override
        public void onDestroy() {
            if (mLockScreenReceiver != null) {
                unregisterReceiver(mLockScreenReceiver);
                mLockScreenReceiver = null;
            }
            super.onDestroy();
            // 重启服务
            startService(new Intent(this, AppService.class));
            
            
        }
    
    }

    源码有点多就不一一贴出来了,直接下载源码即可。

    有兴趣的小伙伴可以参考,一起研究。

    源码点击下载:https://github.com/DickyQie/android-system

  • 相关阅读:
    通过JDBC连接HiveServer2
    HDP-2.6.1安装
    VMWare虚拟机NAT模式静态IP联网配置
    基于ansj_seg和nlp-lang的简单nlp工具类
    修改ES使用root用户运行
    使用MapReduce将HDFS数据导入到HBase(三)
    HBase表操作
    使用SpringMVC解决Ajax跨域问题
    SpringBoot之Web开发——webjars&静态资源映射规则
    thymeleaf+springboot找不到html,只返回了字符串
  • 原文地址:https://www.cnblogs.com/zhangqie/p/8431566.html
Copyright © 2011-2022 走看看