0

I use openOptionsMenu() to open the menu in applications with special GUI - for example, apps that only show graphics (fullscreen apps without toolbars etc.), upon a long press of the screen.

I can see that I made it work in the past on other applications, and I suppose that it was by using in the Manifest,

    android:minSdkVersion="15"
    android:targetSdkVersion="15"

I am now unable to make this work (the code would be):

    myButton.setOnLongClickListener(
            new OnLongClickListener() {
                @Override public boolean onLongClick(View v) {
                    openOptionsMenu();
                    return false;
                }
            }
            );

I think that Android Studio is using the wrong SDK. In fact,

  • the values I put in the Manifest ("min" and "target" set to 15) are overridden;

  • the values used should be those of build.gradle - and again, I set "compile", "min" and "target" set to 15, but I do not see the app working properly and I think the SDK selection may not be happening;

  • as I check the produced APK the Manifest entries for the SDK (minSdkVersion, targetSdkVersion) are missing.

The build.gradle file according to the Android Studio interface shows:

    android {
        compileSdkVersion 15
        buildToolsVersion "28.0.2"
        defaultConfig {
            applicationId '[...AppID...]'
            minSdkVersion 15
            targetSdkVersion 15
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            }
        }
        productFlavors {
        }
    }

As written above, the AndroidManifest.xml in the compiled APK (after apktool -d) does not mention any SDK selection.

I expect that the app compiled for SDK 15 would open the (very required) menu upon call of openOptionsMenu(). What the compiled app does now, upon debugging, is to go instead in the method that would /close/ the menu (clearly a satanic intention).

EDIT: the information about the specific case of Google butchering openOptionsMenu() after some SDK version is at openOptionsMenu function not working in ICS?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
mdp
  • 33
  • 8
  • try returning true from the longclick method – Vivek Mishra Dec 26 '18 at 11:09
  • @Vivek Mishra: bur that 'return false;' occurs _after_ the openOptionsMenu() call, which already sends you (through breakpoint and step-in) first to some unrecognized bytecode, and immediately after to the Window.closePanel() method. – mdp Dec 26 '18 at 11:15

1 Answers1

0

I suppose I have made a mistake. I realized that my past, working code did not just compile for SDK 15, it also contained an override as follows, and as suggested by user tallicalord in the previously linked page:

@Override public void openOptionsMenu() {
    Configuration cfg = getResources().getConfiguration();
    if( (cfg.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK)>Configuration.SCREENLAYOUT_SIZE_LARGE){
        int shelf = cfg.screenLayout;
        cfg.screenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
        super.openOptionsMenu();
        cfg.screenLayout = shelf;
    }else{
        super.openOptionsMenu();
    }
}

So it is possible that the SDK selection, even though more mysterious in Android-Gradle (which removes references in the Manifest), was not the problem.

I shall note that it is very unfortunate how Google manages to make people waste uncountable hours for problems that did not need to exist at all.

mdp
  • 33
  • 8