机器人:以电话(kiosk模式)的完全控制,这可能吗?怎么样? [英] Android: Taking complete control of phone(kiosk mode), is it possible? How?

查看:248
本文介绍了机器人:以电话(kiosk模式)的完全控制,这可能吗?怎么样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有,我们对手机和贷款的电话安装到用户在一定时间内的程序。我们希望单独使用的手机来运行我们的应用程序(没有电话,没有游戏,什么都没有)。这种手机将扎根。

We have a program that we install on the phones and loan the phones to users for a certain period. We would like the phones to be used solely for running our application (no phone calls, no games, no nothing). The phones will be rooted.

因此​​,我们需要的东西:

So the things we need:

  • 在全屏运行,不出意外将是可见
  • Home键和其他设备的按钮将无法正常工作
  • 在我们的应用程序会在启动时自动运行

有不必被黑客证明,但应足以prevent平均用户与装置搞乱。

It doesn't have to be "hacker proof", but should be sufficient to prevent average user messing with the device.

这可能吗?我已经做了在Symbian和放大器类似的事情; Windows Mobile的,但是我没有这个东西在Android上很多经验。怎么可能实现这一目标?

Is this possible? I have done similar things on Symbian & Windows Mobile but I don't have much experience with this stuff on Android. How may this be achieved?

更新2015年:如果您不介意限制你的应用程序,以单一的手机厂商,三星电子推出了KNOX SDK,可以让你实现kiosk模式,并更容易地没有生根的手机。查看详情于: https://seap.samsung.com/developer/sdk/knox - 标准 - 机器人

UPDATE 2015: If you don't mind limiting your app to single phone vendor, Samsung has introduced the KNOX SDK that lets you achieve kiosk mode and much more easily without rooting the phone. See details at: https://seap.samsung.com/developer/sdk/knox-standard-android

推荐答案

是的,它是可能的,但你无法控制的 Home键结束通话键。

yes it is possible but you can not control the behaviour of Home key and end call key.

全屏幕中添加安卓主题=@安卓风格/ Theme.NoTitleBar.Fullscreen。在清单文件活动标签

for full screen add android:theme="@android:style/Theme.NoTitleBar.Fullscreen" to activity tag in manifest file.

要禁用来电你要听电话:

To disable incoming call you need to listen phone calls:

import android.app.Service;
import android.os.IBinder;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;

public class MyPhoneStateListener extends Service{

    @Override
    public IBinder onBind(Intent arg0) {
        return null;
    }

    @Override
    public void onCreate() {
        super.onCreate();
            StateListener phoneStateListener = new StateListener();
            TelephonyManager telephonymanager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
            telephonymanager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);

    }

    class StateListener extends PhoneStateListener{
        @Override
        public void onCallStateChanged(int state, String incomingNumber) {
            super.onCallStateChanged(state, incomingNumber);
            switch(state){
                case TelephonyManager.CALL_STATE_RINGING:
                    //Disconnect the call here...
                    break;
                case TelephonyManager.CALL_STATE_OFFHOOK:
                    break;
                case TelephonyManager.CALL_STATE_IDLE:
                    break;
            }
        }
    };

    @Override
    public void onDestroy() {

    }
}

注:停止服务不foget删除监听器,并添加这些权限到你的manifest文件:

Note: While stopping service don't foget to remove the listener and add these permissions to your manifest file:

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

和断开呼叫编程方式:

try{
    TelephonyManager manager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
    Class c = Class.forName(manager.getClass().getName());
    Method m = c.getDeclaredMethod("getITelephony");
    m.setAccessible(true);
    ITelephony telephony = (ITelephony)m.invoke(manager);
    telephony.endCall();
} catch(Exception e){
    Log.d("",e.getMessage());
}

注:添加该文件以断开呼叫: http://dl.dropbox.com/u/31740476/ITelephony.aidl

Note: Add this file to disconnect the call: http://dl.dropbox.com/u/31740476/ITelephony.aidl

要禁用按键,你需要重写:

To disable keys you need to override:

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if(KeyEvent.KEYCODE_MENU == event.getKeyCode() || KeyEvent.KEYCODE_DPAD_LEFT==event.getKeyCode()
            || KeyEvent.KEYCODE_DPAD_DOWN==event.getKeyCode() || KeyEvent.KEYCODE_DPAD_RIGHT==event.getKeyCode()
            || KeyEvent.KEYCODE_DPAD_UP==event.getKeyCode() || KeyEvent.KEYCODE_DPAD_CENTER==event.getKeyCode()
            || KeyEvent.KEYCODE_BACK==event.getKeyCode())
    {
        return false;
    }
    return true;
}

在Home键preSS主屏幕会来,所以你需要实现一个服务,你有没有要实现一个无限的线程来重新启动这样你的应用程序来解决这个问题:

On Home key press the Home screen will come, so to overcome this you need to implement a service and there you need to implement a infinite thread to relaunch your app like this:

public class AppTrackingService extends Service {

    private RunnableThread thread;
    private Context ctx;

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    public void onCreate(){
        super.onCreate();
        ctx = AppTrackingService.this;
        thread = new RunnableThread();
    }

    public void onStart(Intent intent, int startid) {
        try{
            if(thread==null) thread = new RunnableThread();
            thread.startThread();
        }catch(Exception e){  }
    }

    class RunnableThread extends Thread {

        Handler back_handler = new Handler();
        boolean isContinue = false;

        public RunnableThread(){
            isContinue = false;
        }

        public void setIsContinue(boolean val){
            this.isContinue = val;
        }

        public void startThread(){
            isContinue = true;
            start();
        }

        public void run(){
            ActivityManager actMngr = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
            while(isContinue){
                try{
                //Maintain a boolean "isyourapprunning" to know if your app was running or not....
                    if(isyourapprunning){
                    String runningPkg = actMngr.getRunningTasks(1).get(0).topActivity.getPackageName();
                        if (!runningPkg.equals(ctx.getPackageName())){
                                launchApp(ctx.getPackageName());
                            }
                        Thread.sleep(2500);  //2.5 secs
                    }else{
                        isContinue = false;
                        stopSelf();
                    }

                }catch(Exception e){ }
            }//end of while loop
        }

        protected void launchApp(String packageName) {
            Intent mIntent = getPackageManager().getLaunchIntentForPackage(packageName);
            mIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            mIntent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
            if (null != mIntent) {
                try {
                    startActivity(mIntent);
                } catch(Exception e) { }
            }
        }
    }
}

这篇关于机器人:以电话(kiosk模式)的完全控制,这可能吗?怎么样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆