ysnky
ysnky

Reputation: 458

disable rotate for my widget

i've developed and android widget and i do not want to disable rotatation feature of my widget. so it would be render only portraid never landscape mode.

i tried this code but it disabled rotaion for all applications. i just only concider my widget.

    public static void setAutoOrientationEnabled(ContentResolver resolver, boolean enabled) {    
    Settings.System.putInt(resolver, Settings.System.ACCELEROMETER_ROTATION, enabled ? 1 : 0);
}

how can i make it?

thanks

Upvotes: 0

Views: 326

Answers (2)

ρяσѕρєя K
ρяσѕρєя K

Reputation: 132982

You can use accelerometer_rotation for toggle device 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");
}

In manifest.xml:

<uses-permission android:name="android.permission.WRITE_SETTINGS" />

Upvotes: 0

Shankar Agarwal
Shankar Agarwal

Reputation: 34765

You can create a service and register it to the CONFIGURATION_CHANGED event, like this

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);

Upvotes: 1

Related Questions