Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable hardware acceleration, backward compatibility

I have a problem with a function (setLayerType(LAYER_TYPE_NONE, null)) available in api >=11, and my code should run on android 1.6 (API level 4) too. I have tried to use reflection like this:

try {

        Method method = View.class.getMethod("setLayerType", Integer.TYPE, null);
        method.invoke(LAYER_TYPE_NONE, null);
        view.setLayerType(LAYER_TYPE_NONE, null);
    } catch (Throwable e) {
        Log.e("_________________test", "Function not found");
    }

but my app crash at view.setLayerType with java.lang.VerifyError....

Does anybody have any idea how can I workaround this crash and get a backward compatibility with this function in lower level api?

Thanks, Arkde

like image 645
Aurelian Cotuna Avatar asked Jan 18 '23 02:01

Aurelian Cotuna


2 Answers

Just remove

view.setLayerType(LAYER_TYPE_NONE, null);

and you should be fine, for security reasons, Java/Android would first verify that it has at least a shot of running a given class before proceeding, and on older Android OS it doesn't know how to execute "view.setLayerType(LAYER_TYPE_NONE, null);", it would throw a hard Error before any code from that class could be run.

Since you've run the code using reflection, you shouldn't need that line of code anyway.

like image 154
Kai Avatar answered Feb 13 '23 16:02

Kai


This should be useful: http://android-developers.blogspot.com/2009/04/backward-compatibility-for-android.html

If it really has something to do with hardware acceleration, you could add following to your manifest:

<application android:hardwareAccelerated="true">
<activity ... />
<activity android:hardwareAccelerated="false" />
</application>

src: http://developer.android.com/guide/topics/graphics/hardware-accel.html

like image 27
Ferdau Avatar answered Feb 13 '23 15:02

Ferdau