我开发了android小部件,我不想禁用我的小部件的旋转功能。所以它只会渲染出来,而不是横向模式。
我尝试了这段代码,但它禁用了所有应用程序的旋转。我只是简化了我的小部件。
public static void setAutoOrientationEnabled(ContentResolver resolver, boolean enabled) {
Settings.System.putInt(resolver, Settings.System.ACCELEROMETER_ROTATION, enabled ? 1 : 0);
}
我该怎么做?
感谢
答案 0 :(得分:1)
您可以创建服务并将其注册到CONFIGURATION_CHANGED事件,如此
public class MyService extends Service {
@Override
public void onCreate() {
super.onCreate();
BroadcastReceiver bReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
refreshWidget(); // Code to refresh the widget
}
};
IntentFilter intentFilter = new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED);
registerReceiver(bReceiver, intentFilter);
答案 1 :(得分:0)
您可以使用accelerometer_rotation
来切换设备轮换:
String str = Settings.System.getString(paramContext.getContentResolver(), "accelerometer_rotation");
if (str.equals("0"))
{
Settings.System.putString(paramContext.getContentResolver(), "accelerometer_rotation", "1");
}
if (!str.equals("1"))
Settings.System.putString(paramContext.getContentResolver(), "accelerometer_rotation", "0");
}
在manifest.xml中:
<uses-permission android:name="android.permission.WRITE_SETTINGS" />