gpt4 book ai didi

android - 永久全屏显示安卓应用

转载 作者:行者123 更新时间:2023-11-29 14:48:58 25 4
gpt4 key购买 nike

我正在为希望使用平板电脑展示交互式广告和游戏的客户开发一款应用。平板电脑将放置在支架中,避免使用任何物理按钮。

我试图让应用程序全屏运行,从顶部滑动后我希望应用程序保持全屏。但是有那么一会儿,状态栏出现了,按钮也出现了。

我的 Activity 代码:

public class OrderActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_order);
hideSystemUi();
getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(
new OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int visibility) {

if (visibility == 0) {
hideSystemUi();
}
}
});
}

private void hideSystemUi() {

getWindow().getDecorView().setSystemUiVisibility(

View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE);

}


}

PD:我知道这种行为在来自市场的应用程序中是不受欢迎的,但在这种特定情况下这是必需的并且是“正确的”。

最佳答案

假设设备已获得 root 权限,您可以通过在终端 shell 中运行以下命令来摆脱底部的按钮:

setprop qemu.hw.mainkeys 1
killall surfaceflinger

您可以在 Android 中以编程方式运行它,例如:

try {
Process process = Runtime.getRuntime().exec("getprop qemu.hw.mainkeys");
BufferedReader prop = new BufferedReader(new InputStreamReader(process.getInputStream()));

if (prop == null || !prop.trim().equals("1")) {
Runtime.getRuntime().exec("setprop qemu.hw.mainkeys 1");
Runtime.getRuntime().exec("killall surfaceflinger");
}
} catch (Exception e) {
e.printStackTrace();
}

这个SO answer在 build.prop 中谈到了这样做,但我无法让它为我工作。另外,通过编程方式,我可以在用户退出应用程序时将其重新打开。

更新了通知栏<​​/strong>

对于顶部的通知栏,我能做的最好的就是阻止它展开。它仍然会弹出,但用户不能对其执行太多操作。

这实际上与我在这里找到的另一个答案略有不同:link .

public static class customViewGroup extends ViewGroup {
public customViewGroup(Context context) {
super(context);
}

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
}

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
Log.v("customViewGroup", "********** Intercepted");
return true;
}
}

// https://stackoverflow.com/questions/25284233/prevent-status-bar-for-appearing-android-modified
public static void interceptNotificationBarSwipe(Context c) {
WindowManager manager = ((WindowManager) c.getApplicationContext().getSystemService(Context.WINDOW_SERVICE));

WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams();
localLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
localLayoutParams.gravity = Gravity.TOP;
localLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |

// this is to enable the notification to recieve touch events
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |

// Draws over status bar
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;

localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
localLayoutParams.height = (int) (50 * c.getResources().getDisplayMetrics().scaledDensity);
localLayoutParams.format = PixelFormat.TRANSPARENT;

customViewGroup view = new customViewGroup(c);

manager.addView(view, localLayoutParams);
}

您还必须将其添加到您的 AndroidManifest.xml 中:

<uses-permission android:name="android.permission.ACCESS_SUPERUSER" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

我只在 Jelly Bean 4.2 (API 17) 及更高版本中使用过它。不确定在那之前它是否有效。

希望对您有所帮助。

如其他回复中所述,这在 L 中变得更容易,也可以使用自定义 ROM 来完成。我的目标是在 KitKat 中运行的程序化解决方案

关于android - 永久全屏显示安卓应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25213100/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com