關於Luancher 開發 ------ 關機功能

try {
    val intent = Intent(
            "android.intent.action.ACTION_REQUEST_SHUTDOWN")
    intent.putExtra("android.intent.extra.KEY_CONFIRM", true)
    // 其中false換成true,會彈出是否關機的確認窗口
    intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
    context!!.startActivity(intent)
} catch (e: Throwable) {
    e.printStackTrace()
}

 

 

或者直接發送廣播

 

 

//                                val intent:Intent = Intent()
//                                intent.action = Intent.ACTION_SHUTDOWN
//                                context!!.sendBroadcast(intent)

 

 

 

 

以上功能都需要系統權限

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章