Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot cast from LegacyContext to Activity #4

Open
dconlisk opened this issue Jul 26, 2012 · 2 comments
Open

Cannot cast from LegacyContext to Activity #4

dconlisk opened this issue Jul 26, 2012 · 2 comments

Comments

@dconlisk
Copy link

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
Copy link
Author

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

@davidshumway
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants