12

Android タブレット用の phonegap で書かれたハイブリッド アプリケーションがあります。ここで、タブレットに自分のアプリケーションのみを表示したいと考えています。基本的に、タブレットは常に自分のアプリケーションのみを実行するキオスク モードにする必要があります。すべてのボタンが無効になるようにします。私はオンラインで解決策を探しましたが、そのうちの1つは「surelock」を使用することですが、上記のすべてを行うわけではありません. 別のオプションは、独自の ROM を作成することですが、それに関する適切なチュートリアルが見つかりませんでした。誰でも私を助けてくれますか?

4

6 に答える 6

1

デバイスをルート化せずに別の解決策があると思います。私の上司はルート化を避けるように私に頼んだので、いくつかの調査の後、私はこの回避策にたどり着きました。その結果、ハッキングは行われず、システム キーは残っていますが、ユーザーはアプリケーションを離れて別のアプリケーションを起動することはできません。だから、私は次の手順を実行しました。

1. マニフェストを編集して、次のように、適切ななしTitleBarでフルスクリーン テーマを設定します。ActionBarActivity

<application
    ...
    android:theme="android:Theme.Holo.NoActionBar.Fullscreen" >

Activity2.クラスのメソッドをオーバーライドして、戻るボタンを無効にしました。

@Override
public void onBackPressed() {
    return;
}

3. 次の文字列をマニフェストに追加します (適切な のインテント フィルター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>

これで、デフォルトのホーム画面をアプリケーションに置き換えることができます。ただし、「最近のアプリ」ボタンをクリックして別のアプリを選択することで、アプリを終了する機能はまだ残っています.

4. アプリを終了する他のすべての方法を回避するために、アクティビティが一時停止されるたびに開始されるサービスを追加しました。このサービスはアプリケーションを再起動し、それに関する通知を送信します。サービスコード:

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");
    }
}

Activity クラスに追加されたコード:

@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あります。「終了」ボタンをクリックするなど、何らかの方法でそれを行うことができます。私の場合、終了するにはパスワードが必要です。

于 2015-04-10T11:35:59.980 に答える