1

Suppose Myactivity.java screen orientation is set to landscape in androidManifest file i.e

android:screenOrientation="landscape"

This activity has a openfileMethod with the following code :-

Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(uriObj, mimeType);
startActivity(intent);

Now is it there any programmatical way to force the chosen app (i.e app selected for opening file) to start in landscape mode only.

If yes how is it possible ? Please let me know in case any more info is required.

Abhinav
  • 1,720
  • 4
  • 21
  • 33

3 Answers3

0

to force your activity to be in portrait mode programatically you have to add this line:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

in onCreate or onResume call your openfileMethod()

Lucian Novac
  • 1,255
  • 12
  • 18
  • what is `activityInfo` here? is it the activity in which my openFilemethod() is written? why do i need to call this method only in oncreate/onResume..won't it make the code very much tightly coupled with the activity lifecycle and reduce the scope of code refactor in future? – Abhinav Mar 14 '14 at 12:19
  • Yes is the activity in which your openFilemethod() is written, you can call the methode where you want... – Lucian Novac Mar 14 '14 at 12:22
0

I think you want to change orientation during runtime. Here is a solution from How to lock orientation during runtime OnCreate:

int currentOrientation = getResources().getConfiguration().orientation;
if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);}
else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
}    
+ yourmethod();
Community
  • 1
  • 1
anotherBug
  • 117
  • 4
0

I don't think it's possible. Why would you want to force this behaviour upon the user? Perhaps if we know why you're trying to force an external app to open landscape, then we might be able to propose an alternative solution for you.

Failing that, you'll need to write your own viewer activity in your application and create an intent to explicitly run that activity.

LairdPleng
  • 948
  • 3
  • 9
  • 28