2015-11-06 13 views
6

私はKiowareとSureLockのアプリケーションを見てきました。彼らは単に錠剤のすべてのコントロールをブロックします。私は、バックボタンのオーバーライドと自宅や最近のタスクのオプションの処理についても気づいています。 しかし、私は彼らがどのようにシステムバーの設定オプションを制御することができたか分かりません。設定が数秒間表示されてから消えます。同様に、スワイプダウンに表示されるモバイルのステータスバーはブロックする必要があります。アンドロイドタブレット/モバイルのステータスバーをブロック/無効にする

誰かがそれについて考えているなら、それを分けてください。どんな指導/助けもありがとうございます。

See the attached image selected portion which I need to block/disable

+0

最近の仕事はロリポップで手に入りましたか?それもあなたにとって問題になるでしょうから、私はすでにこのような状況に遭っています。 – Androider

+0

@Androiderそれは問題ではありません。私は設定オプションを探しています。それは完全ロックアプリケーションでは無効になっています。あなたはそれについて何か考えていますか? –

+0

システム・バーの上にビューを追加する – Androider

答えて

0

最後に、私は上記の問題の解決策を見出しました。 onWindowFocus change私はシステムで生成されたダイアログを閉じて、問題は解決しました。以下はサンプルコードです。

@Override 
    public void onWindowFocusChanged(boolean hasFocus) { 
     super.onWindowFocusChanged(hasFocus); 

     if(!hasFocus) 
     {// Close every kind of system dialog 
      Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); 
      sendBroadcast(closeDialog); 

     } 

    } 

更新:ダウン方法以下のスクリーン使用上のスワイプに表示されるステータスバーをブロックするモバイルで

private Handler collapseNotificationHandler; 
      @Override 
      public void onWindowFocusChanged(boolean hasFocus) { 
       boolean currentFocus = hasFocus; 
       if (!hasFocus) { 
        collapseNow(true,currentFocus); 

       } 

      } 


    public void collapseNow(final boolean shouldCollapse, final boolean currentFocus) { 

       // Initialize 'collapseNotificationHandler' 
       if (collapseNotificationHandler == null) { 
        collapseNotificationHandler = new Handler(); 
       } 

       // If window focus has been lost && activity is not in a paused state 
       // Its a valid check because showing of notification panel 
       // steals the focus from current activity's window, but does not 
       // 'pause' the activity 
       if (!currentFocus && !isPaused) { 

        // Post a Runnable with some delay - currently set to 50 ms 
        collapseNotificationHandler.postDelayed(new Runnable() { 

         @Override 
         public void run() { 

          // Use reflection to trigger a method from 'StatusBarManager'     

          Object statusBarService = getSystemService("statusbar"); 
          Class<?> statusBarManager = null; 

          try { 
           statusBarManager = Class.forName("android.app.StatusBarManager"); 
          } catch (ClassNotFoundException e) { 
           e.printStackTrace(); 
          } 

          Method collapseStatusBar = null; 

          try { 

           // Prior to API 17, the method to call is 'collapse()' 
           // API 17 onwards, the method to call is `collapsePanels()` 

           if (Build.VERSION.SDK_INT > 16) { 
            collapseStatusBar = statusBarManager.getMethod("collapsePanels"); 
           } else { 
            collapseStatusBar = statusBarManager.getMethod("collapse"); 
           } 
          } catch (NoSuchMethodException e) { 
           e.printStackTrace(); 
          } 

          collapseStatusBar.setAccessible(shouldCollapse); 

          try { 
           collapseStatusBar.invoke(statusBarService); 
          } catch (IllegalArgumentException e) { 
           e.printStackTrace(); 
          } catch (IllegalAccessException e) { 
           e.printStackTrace(); 
          } catch (InvocationTargetException e) { 
           e.printStackTrace(); 
          } 

          // Check if the window focus has been returned 
          // If it hasn't been returned, post this Runnable again 
          // Currently, the delay is 50 ms. You can change this 
          // value to suit your needs. 
          if (!currentFocus && !isPaused) { 
           collapseNotificationHandler.postDelayed(this, 50); 
          } 

         } 
        }, 0); 
       } 
      } 

"isPaused"ブール値。アプリケーションが一時停止状態のときにtrueに設定されます。

2

あなたはWindowManagerthis例に従う)を使用してdesidered位置に透明Viewを追加しようとすることができます。このようにして、ユーザからののタップイベントは、インターセプトされます。

あなたがシステムバーオーバーレイする必要があるため、適切なフラグ/タイプを設定に必ず:システムバーにオーバーレイする透明カスタムビューを追加

WindowManager.LayoutParams dismissParams = new WindowManager.LayoutParams(
         viewWidth, 
         viewHeight, 
         WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, //you can also try with TYPE_SYSTEM_OVERLAY, TYPE_SYSTEM_ERROR 
         WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, 
         PixelFormat.TRANSPARENT); 
+0

これまで説明したようにビューを追加しようとしましたが、そのビューはシステムバーに表示されません。 –

+0

@NareshSharma TYPE_SYSTEM_OVERLAYで試しましたか? – bonnyz

+0

そのフラグでも機能しません。 –

3

トリックがあるが、そのタッチ、ドラッグなどのすべてのユーザーのやりとりがカスタムビューで消費されます。ここで

は、作業コードです:

windowManager = (WindowManager) getSystemService(WINDOW_SERVICE); 

activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); 

statusBarOverlay = new CustomViewGroup(this); 

final 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 receive 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 * getResources().getDisplayMetrics().scaledDensity); 
localLayoutParams.format = PixelFormat.TRANSPARENT; 

windowManager.addView(statusBarOverlay, localLayoutParams); 

カスタムViewGroup

public 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) { 
      return true; 
     } 
    } 

私は多くの理由のために別のアプリにロック機能を分離しているのに私のアプリに機能をロックする私自身が行っています。より多くの情報を求めることができます。必要に応じてここに記入します。

関連する問題