我在phonegap上为android平板电脑编写了一个混合应用程序。现在,我希望平板电脑只显示我的应用程序。基本上,我希望平板电脑总是处于kiosk模式,只运行我的应用程序。所以所有的按钮都被禁用了。我已经在网上寻找解决方案,其中之一是使用"surelock",但它并不能做到上述所有。另一个选择是写我自己的ROM,但我找不到任何好的教程。有人能帮我吗?
发布于 2014-08-21 07:47:45
我做了很多研究,现在终于对我所得到的感到满意了。
你基本上有两个选择:
因此,我将解释第二个选择。
首先,您需要根治您的设备。有各种各样的方法,但我更喜欢通过oneclick软件生根。对于中国的药片,您可以使用VROOT,对于比较流行的,您可以使用Kingo。
现在,你有你的设备根,我们可以摆脱顶部和底部的酒吧。
private void hideBar(){
try
{
Process proc = Runtime.getRuntime().exec(new String[]{"su","-c","service call activity 42 s16 com.android.systemui"});
proc.waitFor();
}
catch(Exception ex)
{
Toast.makeText(getApplicationContext(), ex.getMessage(), Toast.LENGTH_LONG).show();
Log.e("ROOT ERROR", ex.getMessage());
}
}这将使顶部和底部的酒吧消失。然而,您可能需要一种方式来再次显示酒吧。为此,您可以使用:
public void showBars(){
try
{
String command;
command = "LD_LIBRARY_PATH=/vendor/lib:/system/lib am startservice -n com.android.systemui/.SystemUIService";
String[] envp = null;
Process proc = Runtime.getRuntime().exec(new String[] { "su", "-c", command }, envp);
proc.waitFor();
}
catch(Exception ex)
{
Toast.makeText(context.getApplicationContext(), ex.getMessage(), Toast.LENGTH_LONG).show();
}
}好的,剩下的就是让您的应用程序在启动时启动。为此,你可以找到许多教程,只有谷歌。
发布于 2016-05-17 09:34:34
有了Android L版本(Lollipop),就有了一个名为定位的功能,它几乎相当于Kiosk模式。这里有一个链接,解释了如何设置它。
我相信苹果是在iOS中第一次引入这一点的。尽管OP没有提出要求,但我也提供了iOS的详细信息:
安卓:http://www.cnet.com/how-to/ho-to-pin-apps-in-android-5-lollipop/
iOS:http://www.webascender.com/Blog/ID/447/How-to-Setup-Kiosk-Mode-Lock-Your-iPad-to-Just-One-App#.VzrO2ZN95E5
发布于 2015-04-10 11:35:59
我认为有一个替代的解决方案,没有生根的装置。我的老板要求我避免生根,所以在做了一些研究之后,我找到了这个解决办法。结果,没有进行黑客攻击,系统密钥仍然保留,但用户无法离开应用程序并启动另一个应用程序。所以,我按照步骤做了。
TitleBar和ActionBar的全屏主题设置为适当的Activity,如下所示:<application
...
android:theme="android:Theme.Holo.NoActionBar.Fullscreen" >Activity类的方法禁用后退按钮:@Override
public void onBackPressed() {
return;
}Activity的意图筛选器):<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>现在,您可以用应用程序替换默认主屏幕。但是,通过点击“最近的应用程序”按钮并选择另一个应用程序,退出应用程序的能力仍然存在。
public class RelaunchService extends Service {
private Notification mNotification;
private Timer mTimer;
public RelaunchService() {
}
@Override
public void onCreate(){
super.onCreate();
if (mNotification == null) {
Context context = getApplicationContext();
Intent notificationIntent = new Intent(this, FullscreenActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);
Notification.Builder mBuilder = new Notification.Builder(context)
.setSmallIcon(android.R.drawable.ic_dialog_info)
.setWhen(System.currentTimeMillis())
.setContentIntent(contentIntent)
.setContentTitle("Your app title")
.setContentText("App is being relaunched");
mNotification = mBuilder.getNotification();
mTimer = new Timer("LaunchTimer");
}
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
startForeground(1, mNotification);
mTimer.schedule(new TimerTask() {
@Override
public void run() {
Intent intent = new Intent(RelaunchService.this, YourActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
}, 300);
return START_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
stopForeground(true);
mTimer.cancel();
}
@Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not yet implemented");
}
}添加到活动类中的代码:
@Override
protected void onResume() {
super.onResume();
exitAllowed = false;
Intent servIntent = new Intent(this, RelaunchService.class);
stopService(servIntent);
}
@Override
protected void onPause() {
super.onPause();
savePersistentData();
if (!exitAllowed) {
Intent servIntent = new Intent(this, RelaunchService.class);
startService(servIntent);
}
}当您想关闭应用程序时,应该将exitAllowed布尔变量分配给true。您可以考虑一些方法来做到这一点,例如,单击“退出”按钮。在我的例子中,密码是需要退出的。
https://stackoverflow.com/questions/24627674
复制相似问题