pg-plugin-screen-orientation icon indicating copy to clipboard operation
pg-plugin-screen-orientation copied to clipboard

Cannot cast from LegacyContext to Activity

Open dconlisk opened this issue 13 years ago • 2 comments

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

dconlisk avatar Jul 26 '12 13:07 dconlisk

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

dconlisk avatar Jul 28 '12 12:07 dconlisk

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]);

davidshumway avatar May 24 '13 19:05 davidshumway