Search code examples
androidandroid-studioandroid-activityandroid-orientation

Phone only portrait, tablet all orientations: Cannot resolve symbol 'ActivityInfo'


I have an Android app build with the newest version of Android Studio.

I want to allow only portrait mode on phone but all orientations on tablets.

I followed this answer and also this post.

I made everything as described.

Then I opened the file activity/MainActivity.java.

I looked for this line of code: public void onCreate(Bundle savedInstanceState) {

Then I added the following code below this code:

if(getResources().getBoolean(R.bool.portrait_only)) {
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}

Here's a small snippet:

@Override
public void onCreate(Bundle savedInstanceState) {

    if(getResources().getBoolean(R.bool.portrait_only)) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

ActivityInfo has a red color with the following error message:

Cannot resolve symbol 'ActivityInfo'

It also shows a blue information:

android.content.pm.ActivityInfo? ⌥⏎

Why that? What am I doing wrong?


Solution

  • You need to add the following line at the top of your file below package name to import ActivityInfo: import android.content.pm.ActivityInfo;