Friday, June 24, 2011

Start Display Setting, start activity with Settings.ACTION_DISPLAY_SETTINGS

Start Display Setting, start activity with Settings.ACTION_DISPLAY_SETTINGS

package com.exercise.AndroidIntentDisplaySetting;

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

public class AndroidIntentDisplaySettingActivity extends Activity {

Button btnDisplaySetting;
Intent intentDisplaySetting;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnDisplaySetting = (Button)findViewById(R.id.displaySetting);

intentDisplaySetting = new Intent(Settings.ACTION_DISPLAY_SETTINGS);
ResolveInfo resolveInfo = getPackageManager().resolveActivity(intentDisplaySetting,0);

if(resolveInfo == null){
Toast.makeText(AndroidIntentDisplaySettingActivity.this,
"Not Support!",
Toast.LENGTH_LONG).show();
btnDisplaySetting.setEnabled(false);
}else{
btnDisplaySetting.setEnabled(true);
}

btnDisplaySetting.setOnClickListener(new Button.OnClickListener(){

public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(intentDisplaySetting);
}});
}
}


No comments: