Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 4    Views: 65

Sherry
Lost but trying
Profile
Posts: 135
Reg: Jan 05, 2013
South Africa
11,650
05/16/15 02:00 PM (9 years ago)

Android - Prevent rotation on certain screens

I'm trying to create my first Android Phone app and am a completely lost newbie trying to find a solution to keep all the screens except the pdf doc plugin screens in Portrait. I want to allow the pdf doc screens to rotate to either portrait or landscape as the user wants. @LeonG helped me with my iOS app previously and @AlanMac added this previous forum post from 2 years ago as a possible solution for Android http://www.buzztouch.com/forum/thread.php?tid=AE0B1A40BCED1E300772DB7&currentPage=1 but I couldn't get it to work and code looks different on Android Studio so I might have pasted it in the wrong place but added it about 4 lines below the existing code under onCreate and then I did a clean and run but the app screen still rotated.
 
CMCOFFEE
Android Fan
Profile
Posts: 2017
Reg: Jan 04, 2013
Amarillo, Texas
26,670
like
05/16/15 07:35 PM (9 years ago)
in OnCreateView method under : View thisScreensView..... try this: getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); From what I heard and read you can only set activity to certain orientations on activity,which all screens run off of the same activity,so I was thinking you might have to make another activity,etc, but that might work,or it might make them all portrait.If it does make them all portrait on the ones you dont want to make portrait add this: getActivity().setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
05/16/15 08:02 PM (9 years ago)
Nice, Chris! Adding this to my snippet collection! Cheers! -- Smug
 
LA
Aspiring developer
Profile
Posts: 3278
Reg: Aug 16, 2012
Jerseyville, IL
42,880
like
05/17/15 05:59 AM (9 years ago)
That would be the solution @CMCOFFEE..nice solution! LA
 
Sherry
Lost but trying
Profile
Posts: 135
Reg: Jan 05, 2013
South Africa
11,650
like
05/17/15 09:49 AM (9 years ago)
Thank you so much for your help I REALLY appreciate it and now this part of my app works perfectly.
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.