本网站(662p.com)打包出售,且带程序代码数据,662p.com域名,程序内核采用TP框架开发,需要联系扣扣:2360248666 /wx:lianweikj
精品域名一口价出售:1y1m.com(350元) ,6b7b.com(400元) , 5k5j.com(380元) , yayj.com(1800元), jiongzhun.com(1000元) , niuzen.com(2800元) , zennei.com(5000元)
需要联系扣扣:2360248666 /wx:lianweikj
Android一键锁屏实现
追忆似水年华 · 607浏览 · 发布于2019-10-21 +关注

第一步

配置AndroidManifest.xml文件


第二步

public class PowerService extends IntentService {

    public static final String POWER_OFF = "org.foyou.onekeylock.POWER_OFF";
    
    public PowerService() {
        super("PowerService");
    }
    @Override
    protected void onHandleIntent(@Nullable Intent intent) {
        if (intent != null && POWER_OFF.equals(intent.getAction())) {
            try {
                Object power = getSystemService(Context.POWER_SERVICE);
                if (power != null && (power instanceof PowerManager)) {
                    PowerManager powerManager = (PowerManager) power;
                    powerManager.getClass().getMethod("goToSleep", new Class[]{Long.TYPE}).invoke(powerManager, new Object[]{Long.valueOf(SystemClock.uptimeMillis())});
                }
            } catch (Exception e) {
                System.out.println(e.toString());
            }
        }
    }
}

第三步

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Intent intent = new Intent(this, PowerService.class);
        intent.setAction(PowerService.POWER_OFF);
        startService(intent);
        finish();
    }

从某Rom中提取出来的代码,我的手机由root,其他手机没试过,我的OK。瘦了一下身,保持大小8KB以内。


相关推荐

android下vulkan与opengles纹理互通

talkchan · 1158浏览 · 2020-11-23 10:37:39
Android 使用RecyclerView实现轮播图

奔跑的男人 · 2166浏览 · 2019-05-09 17:11:13
微软发布新命令行工具 Windows Terminal

吴振华 · 860浏览 · 2019-05-09 17:15:04
Facebook 停止屏蔽部分区块链广告

· 746浏览 · 2019-05-09 17:20:08
加载中

0评论

评论
分类专栏
小鸟云服务器
扫码进入手机网页