【问题标题】:Android Orientation change by force when using ACTION_VIEW intent使用 ACTION_VIEW 意图时强制更改 Android 方向
【发布时间】:2012-03-27 08:04:58
【问题描述】:

我有横向模式的应用程序。

我将属性“android:screenOrientation="landscape"”放在清单文件中。

我的应用程序有以下代码。

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("tstore://someAppsId"));
activity.startActivity(intent);

在韩国一般有安卓的T-store应用。 T-store 应用程序交易 url 架构“tstore://”。

我的代码只是打开T-store应用程序。

很遗憾,T-store 应用只支持人像。

有问题。

就在打开 t-store 活动之前,android 操作系统会立即(0.2 秒?)将我的活动方向更改为纵向模式,然后打开 t-store 活动。

支持横向模式的 Android Market App 不会发生这种情况。

在这种情况下有没有办法强烈防止方向改变?

【问题讨论】:

  • 回到应用后,应用又切换到横向了吗?

标签: android openurl


【解决方案1】:

在您的活动中添加以下代码。

肖像

@override
protected void onResume(){
 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT );
}

横向

@override
protected void onResume(){
 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE );
}

【讨论】:

    【解决方案2】:

    尝试将android:configChanges="orientation" 属性添加到清单文件中。

    【讨论】:

    • 但如果我们已经将android:screenOrientation="landscape" 设置为我们的活动,那么android:configChanges="orientation" 这将没有任何帮助。
    【解决方案3】:

    只需从代码中设置活动的方向,这样就可以更容易地根据您的要求控制方向。设置方向的代码是,纵向方向

         setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT );
    

    对于横向,

         setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多