开发者

Detecting screen orientation change from service [duplicate]

This question already has answers here: How do I use a service to monitor Orientation change in Android (4 answers) Closed 9 years ago.

A pretty simple and straightforward question... 开发者_运维知识库is it possible for a service to detect screen orientation changes? If so, how?


This link will answer your question: How do I use a service to monitor Orientation change in Android

You can also create a BroadcastReceiver that listens for Intent.ACTION_CONFIGURATION_CHANGED ("android.intent.action.CONFIGURATION_CHANGED")


Try this code

@Override
public void onConfigurationChanged(Configuration newConfig) {
    Log.d("tag", "config changed");
    super.onConfigurationChanged(newConfig);

    int orientation = newConfig.orientation;
    if (orientation == Configuration.ORIENTATION_PORTRAIT)
        Log.d("tag", "Portrait");
    else if (orientation == Configuration.ORIENTATION_LANDSCAPE)
        Log.d("tag", "Landscape");
    else
        Log.w("tag", "other: " + orientation);

    ... 
}

in android manifest file

<activity android:name="..."
    android:label="@string/app_name"
    android:screenOrientation="sensor"
    android:configChanges="orientation|keyboardHidden">
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜