Cannot cast from LegacyContext to Activity
Hi there,
I'm getting an error in ScreenOrientation.java, line 30: Cannot cast from LegacyContext to Activity
The line of code is: Activity activity = (Activity)this.ctx;
Any ideas what I'm doing wrong here? I'm using Cordova 2.0.0, Eclipse 4.2.0 - all the latest versions as far as I know.
Thanks,
David
OK I got this to work with a few changes:
replace line
Activity activity = (Activity)this.ctx;
with
Activity activity = cordova.getActivity();
in ScreenOrientation.java (line 30).
Replace the javascript call to PhoneGap.exec with
cordova.exec(null, null, "ScreenOrientation", "set", [str]);
Note that the first two parameters are callback functions, which I'm not using, which is why I'm passing null for those parameters.
Cheers,
David
Thanks to dconlisk
For use with Cordova 2.5.0
Note that the following require API level 9: android.content.pm.ActivityInfo#SCREEN_ORIENTATION_REVERSE_LANDSCAPE android.content.pm.ActivityInfo#SCREEN_ORIENTATION_FULL_SENSOR android.content.pm.ActivityInfo#SCREEN_ORIENTATION_SENSOR_LANDSCAPE android.content.pm.ActivityInfo#SCREEN_ORIENTATION_SENSOR_PORTRAIT android.content.pm.ActivityInfo#SCREEN_ORIENTATION_REVERSE_PORTRAIT
File: ScreenOrientation.java
Change: import com.phonegap.api.Plugin; import com.phonegap.api.PluginResult;
To: import org.apache.cordova.api.Plugin; import org.apache.cordova.api.PluginResult;
Change: Activity activity = (Activity)this.ctx;
To: Activity activity = cordova.getActivity();
File: pg-plugin-screen-orientation.js
Change: PhoneGap.exec(success, fail, "ScreenOrientation", "set", [str]);
To: cordova.exec(null, null, "ScreenOrientation", "set", [str]);