1
0

More than 3 years have passed since last update.

【Android / Kotlin】USB Debuggingモードでアプリ起動を拒否する

Posted at

セキュリティのため、USB Debuggingモードの場合に起動を拒否する必要があり実装しました。
最初に起動するActivity内に記載します。

Screen Shot 2021-05-28 at 9.44.38.png

@AndroidEntryPoint
class SomeActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        if (isDebuggingMode()) {
            restrictOperation()
        }
    }
    private fun isDebuggingMode (): Boolean = false
       Settings.Secure.getInt(
           contentResolver,
           Settings.Secure.ADB_ENABLED, 0) != 0

    private fun restrictOperation () {
        AlertDialog.Builder(this)
            .setTitle("USBデバックをOFFにしてください")
            .setMessage("ご利用の端末はUSBデバックがONになっているため、ご利用いただけません。")
            .setCancelable(false)
            .setPositiveButton("OK") { _, _ ->
                finish()
            }
            .show()
    }
1
0
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
1
0