Help us understand the problem. What is going on with this article?

開発者向けオプションをコードから開く

More than 3 years have passed since last update.

概要

社内向けのデザイン確認アプリに「開発者向けオプション」を開くボタンを付けたくなったのでメモです。開発者向けオプションが有効かどうかを判定し、有効ならば開発者向けオプションを開きます。

開発者向けオプションが有効かの判定

Settings.Secure.getIntメソッドを使用します。Settings.Global.DEVELOPMENT_SETTINGS_ENABLEDフィールドはAPIレベル17以上で有効です。

戻り値が1ならば開発者向けオプションが有効になっています。

boolean isEnable = Settings.Secure.getInt(this.getContentResolver(),
                Settings.Global.DEVELOPMENT_SETTINGS_ENABLED , 0) == 1;

開発者向けオプションのオープン

以下のようにintentを投げることで開発者向けオプションを開くことができます。

Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS);
startActivity(intent);

最終的なコード

開発者向けオプションが有効かどうかを判別し、有効ならばintentを投げて開くコードは最終的には以下のようになります。

boolean isEnable = Settings.Secure.getInt(this.getContentResolver(),
                Settings.Global.DEVELOPMENT_SETTINGS_ENABLED , 0) == 1;

if (isEnable) {
    Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS);
    startActivity(intent);
}
zozotech
70億人のファッションを技術の力で変えていく
https://tech.zozo.com/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした