从服务android更改亮度 [英] changing brightness from Service android
本文介绍了从服务android更改亮度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从服务更改android设备的亮度。我已经看到了很多关于堆栈溢出的问题,但是没有一个问题解决了我的问题。
I want to change brightness of android device from a service. I have seen a lot of questions on stack overflow on this but none of them has solved my problem.
我已经完成了从settingsManger中设置亮度的一切工作,开始了新的工作活动等
,但没有一个对我有用。
I have done every thing from setting brightness in settingsManger, starting a new activity etc but none of them is working for me.
推荐答案
尝试为
android.provider.Settings.System.putInt(getContentResolver(),
android.provider.Settings.System.SCREEN_BRIGHTNESS,
BRIGHTNESS_Value);
并在Manifest.xml中添加权限
and add permission in Manifest.xml
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<uses-permission android:name="android.permission.CHANGE_CONFIGURATION" />
</manifest>
编辑:
尝试如下:
try as:
public class ExampleService extends Service {
@Override
public void onCreate() {
// The service is being created
// set SCREEN_BRIGHTNESS
android.provider.Settings.System.putInt(getContentResolver(),
android.provider.Settings.System.SCREEN_BRIGHTNESS,
BRIGHTNESS_Value);
/// start new Activity
Intent intent = new Intent(getBaseContext(), ExampleActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplication().startActivity(intent);
}
@Override
public IBinder onBind(Intent intent) {
// A client is binding to the service with bindService()
return mBinder;
}
}
public class ExampleActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// The activity is being created.
}
@Override
protected void onResume() {
super.onResume();
// The activity has become visible (it is now "resumed").
this.finish();
}
}
这篇关于从服务android更改亮度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文