android - How check status of Phone is Landscape or Portrait when Ativity not auto rotation? -
ativity not auto rotation:
<activity android:name=".e028" android:label="@string/app_name" android:screenorientation="portrait" android:theme="@android:style/theme.black.notitlebar" > </activity>
if use onconfigurationchanged , not working:
@override public void onconfigurationchanged(configuration newconfig) { // todo auto-generated method stub super.onconfigurationchanged(newconfig); if (newconfig.orientation == configuration.orientation_landscape) { toast.maketext(this, "landscape", toast.length_short).show(); } else if (newconfig.orientation == configuration.orientation_portrait) { toast.maketext(this, "portrait", toast.length_short).show(); } }
how check status of phone landscape or portrait when ativity not auto rotation?
i think case: must use sensor
my code:
@override public void onsensorchanged(sensorevent event) { // todo auto-generated method stub if (event.values[1] < 6.5 && event.values[1] > -6.5) { if (orientation != 1) { log.d("sensor", "landscape"); // listimage.notifydatasetchanged(); } orientation = 1; } else { if (orientation != 0) { log.d("sensor", "portrait"); // listimage.notifydatasetchanged(); } orientation = 0; } }
but working not best,status of phone portrait: if inclined little , value return landscape.
try this..
getresources().getconfiguration()
return configuration
if(youractivity.getresources().getconfiguration().orientation == configuration.orientation_portrait) { // portrait mode } else { // landscape mode }
edit
Comments
Post a Comment