5

This class is defined under Android:

public abstract class EGLObjectHandle {
    private final long mHandle;

    protected EGLObjectHandle(long handle) {
        mHandle = handle;
    }


    public long getNativeHandle() {
        return mHandle;
    }

}

and also

public class EGLContext extends EGLObjectHandle {
    private EGLContext(long handle) {
        super(handle);
    }

} 

now my problem is that I want to create an EGLContext with my handle. How to do this? before I do it with the function below but it's not working anymore on PIE

  private android.opengl.EGLContext createSharedEGLContextObj(long handle) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
    Class<?> classType =Class.forName("android.opengl.EGLContext"); 
    Class<?>[] types = new Class[] { long.class };
    Constructor constructor=classType.getDeclaredConstructor(types);
    constructor.setAccessible(true);     
    Object object=constructor.newInstance(handle);
    return (android.opengl.EGLContext) object;
  }

I need an EGLContext because I need to pass it to a procedure who require an EGLContext parameter, like for example: createEgl14( android.opengl.EGLContext sharedContext)

zeus
  • 12,173
  • 9
  • 63
  • 184

1 Answers1

2

You pretty much can't. According to Android Restrictions they have restricted JNI and reflection to only SDK interfaces.

I think your final option is request a new feature where they will change the constructor visibility to public.

OughtToPrevail
  • 380
  • 3
  • 10
  • no I absolutely need an instance of EGLContext because I need to pass it to a procedure who require an EGLContext parameter: "createEgl14( android.opengl.EGLContext sharedContext)" – zeus Apr 13 '19 at 18:02
  • Ok interesting, I edited the post to add another way but please explain why reflection fails – OughtToPrevail Apr 13 '19 at 18:59
  • because on Pie reflection is now forbidden and it's make the app crash :( I m getting this handle from my delphi app (pascal code) through JNI interface and I want to share this handle (that is own by the delphi code) with the java code and for this I need to create an EGLContext – zeus Apr 13 '19 at 23:29
  • Well then you can create the EGLContext from JNI. using the "How to create an Object" link I gave you – OughtToPrevail Apr 14 '19 at 07:43
  • Aie, so even with JNI I can't? – zeus Apr 14 '19 at 17:10
  • According to Android no, you can't even with JNI, sorry to have to give the bad news, I saw this isn't your first question about this – OughtToPrevail Apr 14 '19 at 18:29
  • I m just curious, how even Android can create an EGLContext ? because as the creator is private noone even android can create this object – zeus Apr 17 '19 at 17:10
  • I am guessing they use Reflection or JNI as they are allowed to. – OughtToPrevail Apr 17 '19 at 19:37