4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

USBデバッグ有効時にアプリを操作不可能に

Last updated at Posted at 2020-06-14

はじめに

USBデバッグが有効な場合に、ダイアログを出して、操作させないアプリがあったので、自分もやってみた。

実装

USBデバッグが有効かどうかは、 Settings.Global.ADB_ENABLED で取得できる。
https://developer.android.com/reference/android/provider/Settings.Global#ADB_ENABLED

MainActivity.kt
class MainActivity : AppCompatActivity(R.layout.activity_main) {

    override fun onResume() {
        super.onResume()

        val isAdbEnabled = Settings.Global.getInt(contentResolver, Settings.Global.ADB_ENABLED)
        if (isAdbEnabled == 1) {
            AlertDialog.Builder(this)
                .setTitle("USBデバッグがオンになっています")
                .setMessage("USBデバッグをオフにしてください。")
                .setPositiveButton("開発者向けオプションを開く") { _, _ ->
                    startActivity(Intent(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS))
                }
                .setCancelable(false)
                .show()
        }
    }
}

ついでに開発者向けオプションを開けるようにした。

完成

おわりに

USBデバッグが有効な際に、どんな悪いことができるのかはよく分かっていない...

4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?