I have custom implementation of NativeActivity (called MyNativeActivity) for which I need to handle onInputQueueCreated(). Vanilla NativeActivity does by calling getNativePtr() directly.
NativeActivity.java
public void onInputQueueCreated(InputQueue queue) {
if (!mDestroyed) {
mCurInputQueue = queue;
onInputQueueCreatedNative(mNativeHandle, queue.getNativePtr());
}
}
But getNativePtr() being hidden member, It can only be used via JNI which I do for apilevel below 28. And for 33 and above I use AInputQueue_fromJava() provided by android-ndk.
Now the issue is for apilevel 28-32, getNativePtr() does not work and always return null.
Accessing hidden method Landroid/view/InputQueue;->getNativePtr()J (dark greylist, JNI)
So can InputQueue be even converted to AInputQueue ?
Edit:
With suggestion from perplexity.ai, I also tried reflection. this too returns null.
import java.lang.reflect.Method;
import sun.misc.Unsafe;
...
public static long getIQNativePtr(InputQueue queue) {
try {
// Access the hidden method
Method method = InputQueue.class.getDeclaredMethod("getNativePtr");
method.setAccessible(true); // Bypass access checks
return (long) method.invoke(queue); // Invoke and return native pointer
} catch (Exception e) {
e.printStackTrace();
return 0; // Handle error appropriately
}
}
...
I have custom implementation of NativeActivity (called MyNativeActivity) for which I need to handle onInputQueueCreated(). Vanilla NativeActivity does by calling getNativePtr() directly.
NativeActivity.java
public void onInputQueueCreated(InputQueue queue) {
if (!mDestroyed) {
mCurInputQueue = queue;
onInputQueueCreatedNative(mNativeHandle, queue.getNativePtr());
}
}
But getNativePtr() being hidden member, It can only be used via JNI which I do for apilevel below 28. And for 33 and above I use AInputQueue_fromJava() provided by android-ndk.
Now the issue is for apilevel 28-32, getNativePtr() does not work and always return null.
Accessing hidden method Landroid/view/InputQueue;->getNativePtr()J (dark greylist, JNI)
So can InputQueue be even converted to AInputQueue ?
Edit:
With suggestion from perplexity.ai, I also tried reflection. this too returns null.
import java.lang.reflect.Method;
import sun.misc.Unsafe;
...
public static long getIQNativePtr(InputQueue queue) {
try {
// Access the hidden method
Method method = InputQueue.class.getDeclaredMethod("getNativePtr");
method.setAccessible(true); // Bypass access checks
return (long) method.invoke(queue); // Invoke and return native pointer
} catch (Exception e) {
e.printStackTrace();
return 0; // Handle error appropriately
}
}
...
Share
Improve this question
edited Mar 3 at 8:53
dawnmenu
asked Mar 3 at 8:12
dawnmenudawnmenu
415 bronze badges
1 Answer
Reset to default 0There was no need to handle onInputQueueCreated() and onInputQueueDestroyed() like NativeActivity does. Using onTouchEvent() onKeyUp() and onKeyDown() solved the issue.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745104229a4611462.html
评论列表(0条)