hi all...
i did brightness change application for android device..it works correctly but the problem was when i run the application it will change in the brightness setting controller but i was not reflected to the screen display suddenly..when i open brightness setting it will apply..or when the screen timeout it is goin to apply...please do favour for me...
and here is my code
import android.app.Activity;
import android.os.Bundle;
import android.content.SharedPreferences;
import android.os.IHardwareService;
import android.os.ServiceManager;
import android.widget.Toast;
import static android.provider.Settings.System.SCREEN_BRIGHTNESS ;
public class brighttest extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
try {
SharedPreferences settings=
getSharedPreferences("com.anand.brighttest", MODE_PRIVATE);
int val=android.provider.Settings.System.getInt(
getContentResolver(), SCREEN_BRIGHTNESS);
IHardwareService hardware=
IHardwareService.Stub.asInterface( ServiceManager.getService("hardware"));
if(val==255) {
int nval=settings.getInt("ScreenBrightness",128);
if(nval<=0) nval=128;
if(nval>255) nval=255;
Toast.makeText(this,
""+(nval*100/255)+"% Brightness",
Toast.LENGTH_LONG).show();
android.provider.Settings.System.putInt(getContent Resolver(),
SCREEN_BRIGHTNESS, nval);
if(hardware!=null) hardware.setScreenBacklight(nval);
} else {
android.provider.Settings.System.putInt(getContent Resolver(),
SCREEN_BRIGHTNESS, 255);
Toast.makeText(this, "Maximum Brightness", Toast.LENGTH_LONG).show();
SharedPreferences.Editor editor = settings.edit();
editor.putInt("ScreenBrightness",val);
editor.commit();
if(hardware!=null) hardware.setScreenBacklight(255);
}
} catch(Throwable er) {
Toast.makeText(this, "Error "+er.getMessage(), Toast.LENGTH_LONG).show();
} finally {
finish();
}
}
}
/*manifest code-----------*/
<?
xmlversion="1.0"encoding="utf-8"?>
<manifestxmlns:android="http://schemas.android.com/apk/res/android"
package="com.anand.brighttest"
android:versionCode="1"
android:versionName="1.0">
<applicationandroid:icon="@drawable/icon"android:label="@string/app_name">
<activityandroid:name=".brighttest"
android:label="@string/app_name">
<intent-filter>
<actionandroid:name="android.intent.action.MAIN"/>
<categoryandroid:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
<uses-permissionandroid:name="android.permission.HARDWARE_TEST"></uses-permission>
<uses-permissionandroid:name="android.permission.WRITE_SETTINGS"></uses-permission>
</manifest>
with regards
anand
Bookmarks