質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.51%
Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Q&A

解決済

1回答

805閲覧

コードで機内モードに変更できない

androidbeginner

総合スコア7

Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

0グッド

0クリップ

投稿2017/07/09 14:32

機内モードへの変更をしたいのですが、うまくできません。
エラーは出ないのですが、機内モードになりません。
コードを載せるのでよろしくお願いします。

Activity

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings;
import android.view.View;
import android.widget.Button;

/**

  • Created by USER on 2017/07/09.

*/

public class MainActivity extends Activity implements View.OnClickListener {
Button button;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button = (Button)findViewById(R.id.button);
button.setOnClickListener(this);

} private void setAIRPLANEMODE(boolean enable){ int value = enable ? 1:0; Settings.System.getInt(getContentResolver(), Settings.System.AIRPLANE_MODE_ON,value); Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); intent.putExtra("state",value); sendBroadcast(intent); } private void setAIRPLANE(int value,boolean state){ Settings.System.putInt(getContentResolver(), Settings.System.AIRPLANE_MODE_ON,value); Intent intent = new Intent(); intent.setAction(Intent.ACTION_AIRPLANE_MODE_CHANGED); intent.putExtra("state",state); sendBroadcast(intent); } @Override public void onClick(View v) { setAIRPLANEMODE(true); }

}

layout

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent">

<Button android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/button" android:text="Button"/>
</LinearLayout>

マニュフェスト

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="jp.abc.yaruki"> <uses-permission android:name="android.permission.WRITE_SETTINGS"/> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> </application>
</manifest>

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

Android4.2以降ではSettings.Systemはリードオンリーに変更されています。
Settings.Globalを使う必要があるので、まずは調べましょう。

投稿2017/07/09 16:54

yona

総合スコア18155

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

androidbeginner

2017/07/15 06:31

ありがとうございました! 確認不足でしたすいません
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.51%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問