[英]Android - Hide notification bar but keep navigation one
I'm creating a kind of Kiosk application
for Android but I must disable the notification bar to avoid the customers to access Wifi
, Bluetooth
or GPS
quick access. 我正在为Android创建一种
Kiosk application
,但必须禁用通知栏,以避免客户访问Wifi
, Bluetooth
或GPS
快速访问。
So far I've rooted the device and disabled the com.android.systemui
package to achieve that. 到目前为止,我已经扎根了设备并禁用了
com.android.systemui
软件包来实现该目的。 The main issue is, as I got only virtual buttons to navigate, I can't go back or go to home screen. 主要问题是,由于只有虚拟按钮可导航,因此无法返回或返回主屏幕。 Basically I'm stucked on the application and I can't do anything.
基本上,我被应用程序卡住了,无法做任何事情。
I've used that code to disable the SystemUI
package: 我使用该代码禁用了
SystemUI
软件包:
pm disable com.android.systemui
Then I've tried to disable the notification bar
using the Java reflection API
. 然后,我尝试使用
Java reflection API
禁用notification bar
。 So far, I've made that code but it doesn't work. 到目前为止,我已经编写了该代码,但是它不起作用。 Basically, it just throws an
exception
saying my application doesn't have the required permission android.permission.STATUS_BAR
whereas it's written in my Manifest
. 基本上,它只是抛出一个
exception
说我的应用程序没有所需的权限android.permission.STATUS_BAR
而它是在Manifest
编写的。
try
{
Object service = getSystemService("statusbar");
Class<?> statusbarManager = Class.forName("android.app.StatusBarManager");
Method collapse = statusbarManager.getMethod("disable", int.class);
collapse.setAccessible(true);
collapse.invoke(service, 0x00000001);
}
catch (Exception e)
{
e.printStackTrace();
}
Did I make something wrong on that part of code ? 我在那部分代码上做错了吗?
An alternative would be to create a System overlay
to create my own navigation bar
, but I haven't find a proper way to trigger a KeyEvent
to the whole system as if it was the "real" buttons. 一种替代方法是创建一个
System overlay
以创建我自己的navigation bar
,但是我还没有找到适当的方法来触发整个系统的KeyEvent
,就好像它是“真实”按钮一样。 But honnestly, I don't think this would be the best and cleanest solution to use. 但坦率地说,我认为这不是使用的最佳,最干净的解决方案。
Any help would be greatly appreciated. 任何帮助将不胜感激。
In styles.xml: 在styles.xml中:
<resources>
<style name="Theme.FullScreen" parent="@android:style/Theme.Holo">
<item name="android:windowNoTitle">false</item>
<item name="android:windowFullscreen">true</item>
</style>
</resources>
Refer to your custom style in your mainfest: 在mainfest中参考您的自定义样式:
<activity android:name=".MyActivity" android:theme="@style/Theme.FullScreen"/>
or TODO it programatically just do 或以编程方式执行
// Remove System bar (and retain title bar)
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
in code it looks like 在代码中看起来像
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
public class ActivityName extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Remove System bar (and retain title bar)
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
// Set your layout
setContentView(R.layout.main);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.