機内モードへの変更をしたいのですが、うまくできません。
エラーは出ないのですが、機内モードになりません。
コードを載せるのでよろしくお願いします。
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">
</LinearLayout><Button android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/button" android:text="Button"/>
マニュフェスト
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
</manifest>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>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/07/15 06:31