Android screen orientation intent

2019-09-13 23:54发布

问题:

My Android app is configured to work on landscape mode only, so I want to make e-mail client, which is created by intent from my app, be landscape too. Is it possible?

Here is my code:

Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/xml");
i.putExtra(Intent.EXTRA_EMAIL, new String[]{"example@mail.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "Feedback");
i.putExtra(Intent.EXTRA_TEXT, "");
try {
    Intent chooser_intent = Intent.createChooser(i, "Send e-mail");  
    startActivity(chooser_intent);
} catch (android.content.ActivityNotFoundException ex) {
    Toast.makeText(getApplicationContext(), "E-mail client not found", Toast.LENGTH_LONG).show();
}

回答1:

It is not possible to specify the orientation of an Activity, if it is external to your app. If an Activity is local to your app (ie. defined in your own Manifest file) - then you could specify the orientation there.

Bottom line, you can not control the orientation of an Application that is not your own (ie. called via system Intent).



回答2:

in android manifest add this android:screenOrientation="landscape" in activity.

example:

 <activity android:name=".yourClientAddressActivity" android:screenOrientation="landscape"></activity>


回答3:

If the screen device is already in the landscape orientation, then the new email activity should use it if it supports it; otherwise, it will go into the portrait mode but then, you can't do anything about that because it doesn't support the landscape orientation in the first place.