PhoneGap - Forcing Landscape orientation
Have you tried this?
android:screenOrientation="portrait"
Inside the AndroidManifest.xml
file, where you have declared your activity, just add the above line.
For example:
<activity
android:name=".Activity.SplashScreenActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action
android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
How to prevent a Phonegap application to switch to landscape view
Ok, so I got it: The reason Phonegap ignored the <preference name="orientation" value="portrait" />
in the config.xml
file is because my app was in debug mode. once I created a release version it stopped from going to landscape.
Enforce right orientation landscape mode for Phonegap/Cordova iOS app
Solution found:
<gap:config-file platform="ios" parent="UISupportedInterfaceOrientations" overwrite="true">
<array>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
PhoneGap 3.0.0 Locking orientation
For locking orientation in IOS : just open the project in Xcode and click on project and inside summary you can select the orientations
FOr Android
add android:screenOrientation="landscape"
to each activity eg:
<activity android:name=".SomeActivity"
android:label="@string/app_name"
android:screenOrientation="landscape">
Device: force orientation landscape (Phonegap JQueryMobile)
This isn't recommended but you could do:
$('body').css({
"-webkit-transform": "rotate(90deg)"
put other browsers here
});
or just in css
#page {
transform:rotate(90deg);
-ms-transform:rotate(90deg); /* IE 9 */
-moz-transform:rotate(90deg); /* Firefox */
-webkit-transform:rotate(90deg); /* Safari and Chrome */
-o-transform:rotate(90deg); /* Opera */
}
Phonegap landscape not detecting orientation for 90 and -90
Use native code as plugin ad call it using javascript. also add it in config.xml. and in CDViewController change Autorotate - return NO. If you want a detailed solution then let me know. I have solved this same condition.
Update : my Solution
Create a new js file as ScreenOrientation.js and insert the below code,
var ScreenOrientation = {
//alert(orientation);
callScreenOrientationNative: function(success,fail,orientation) {
return Cordova.exec( success, fail,
"ScreenOrientation",
"screenorientationFunction",
[orientation]);
}
};
and add the above file in index.html as below,
<script type="text/javascript" src="ScreenOrientation.js"></script>
Add the below function in any added js file(in my project i have added a script.js file to add common functions),
function callScreenOrientation(orientation) {
ScreenOrientation.callScreenOrientationNative(nativePluginResultHandler,nativePluginErrorHandler,orientation);
}
function nativePluginResultHandler (result) {
}
function nativePluginErrorHandler (error) {
}
In config.xml add the below under feature name,
<!-- Screen Orientation custom plugin to display reports page. -->
<feature name="ScreenOrientation">
<param name="ios-package" value="ScreenOrientation"/>
</feature>
Under Plugins add (For cordova < 3.0),
<plugins>
<plugin name="ScreenOrientation" value="ScreenOrientation" />
</plugins>
On Cordova projects > Plugins right click and select new file, then from iOS select Cocoa touch then Select objective-C Class and click next, in class name insert "ScreenOrientation" and in Subclass of "CDVPlugin" and click next and click create.
Enter the below in ScreenOrientation.h,
#import <Cordova/CDV.h>
@interface ScreenOrientation : CDVPlugin
- (void) screenorientationFunction:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
@end
Enter the below in ScreenOrientation.m,
#import "ScreenOrientation.h"
@implementation ScreenOrientation
- (void) screenorientationFunction:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options {
[arguments pop];
NSString *orientation = [arguments objectAtIndex:0];
if ( [orientation isEqualToString:@"LandscapeLeft"] ) {
NSLog(@"Landscape Left");
[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeLeft];
}
else if ( [orientation isEqualToString:@"LandscapeRight"] ) {
NSLog(@"Landscape Right");
[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeRight];
}
else if ( [orientation isEqualToString:@"Portrait"] ) {
NSLog(@"Portrait");
[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationPortrait];
}
else if ( [orientation isEqualToString:@"PortraitUpsideDown"] ) {
NSLog(@"Portrait upSide Down Left");
[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationPortraitUpsideDown];
}
}
@end
In Cordova project click search and search for "shouldAutoRotate and find the below and change the return, by default it will be 'YES' change it to 'NO'.
CDVViewController.m
- (BOOL)shouldAutorotate
{
return NO;
}
And in project settings, in Device orientations check all options (not important though),
Project Settings > Device orientation > Tick all 4 options.
and call it from your project like this,
callScreenOrientation('LandscapeLeft');
callScreenOrientation('LandscapeRight');
callScreenOrientation('Portrait');
callScreenOrientation('PortraitUpsideDown');
Related Topics
In Android Edittext, How to Force Writing Uppercase
How to Use Onsaveinstancestate() and Onrestoreinstancestate()
How to Implement Cookie Handling on Android Using Okhttp
How to Get the Current Page Number of a Viewpager for Android
Converting Yuv->Rgb(Image Processing)->Yuv During Onpreviewframe in Android
How to Disable Keypad Popup When on Edittext
Broadcastreceiver + Sms_Received
Restoring State of Textview After Screen Rotation
Android Studio Not Deploying Changes to App
Using Seekbar to Control Volume in Android
Android: Scrollview Force to Bottom
Using Jaxb with Google Android
How to Style the Drawerarrowtoggle from Android Appcompat V7 21 Library
Android: Using Webview Outside an Activity Context
How to Scale Bitmap to Screen Size