Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setRequestedOrientation cannot find symbol in react-native

I want to enable rotation only in tablets on Android. I Created bools.xml with this code

<resources>
    <bool name="portrait_only">false</bool>
</resources>

and put in MainApplication.java

public class MainApplication extends Application implements ReactApplication {

  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {

    ...

    @Override
      public void onCreate() {
        if(getResources().getBoolean(R.bool.portrait_only)){
          setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }
        super.onCreate();
     } 
  }
}

I get error: cannot find symbol setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

like image 479
user1602300 Avatar asked Apr 15 '26 06:04

user1602300


1 Answers

Application doesn't have setRequestedOrientation() method — Activity does. So you should move the code into your BaseActivity onCreate().

like image 164
Artur Dumchev Avatar answered Apr 16 '26 21:04

Artur Dumchev