2015-11-06 30 views
6

Tôi đã thấy các ứng dụng Kioware và SureLock. Chúng đơn giản chặn mọi điều khiển trong máy tính bảng. Tôi biết về việc ghi đè nút quay lại và xử lý các tùy chọn công việc gia đình và gần đây. Nhưng tôi không chắc cách họ quản lý để kiểm soát tùy chọn cài đặt trên thanh hệ thống. Cài đặt xuất hiện trong một vài giây và sau đó biến mất. Trong cùng một cách Statusbar của điện thoại di động xuất hiện trên swipe xuống cần phải được chặn.Chặn/Vô hiệu hóa Thanh trạng thái trong Android/Điện thoại di động

Nếu có ai có ý tưởng về nó, vui lòng chia sẻ nó. Mọi hướng dẫn/trợ giúp đều được đánh giá cao.

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

+0

Bạn có nhận được các tác vụ gần đây trong kẹo que không? Bởi vì đó cũng sẽ là một vấn đề cho bạn, tôi đã trải qua tình huống này rồi. – Androider

+0

@Androider không phải là vấn đề. Tôi đang tìm tùy chọn cài đặt. Điều đó hoàn toàn bị tắt trong ứng dụng surelock. Bạn có bất kỳ ý tưởng về điều đó? –

+0

thêm chế độ xem trên thanh hệ thống – Androider

Trả lời

0

Cuối cùng tôi đã tìm ra giải pháp cho vấn đề trên. Thay đổi onWindowFocus Tôi vừa đóng hộp thoại do hệ thống tạo ra và vấn đề của tôi đã được giải quyết. bên dưới là mã mẫu.

@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); 

     } 

    } 

Cập nhật:

Trong Điện thoại di động để ngăn chặn thanh trạng thái mà xuất hiện trên swipe xuống về việc sử dụng màn hình bên dưới đường.

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" boolean được đặt đúng khi ứng dụng ở trạng thái Tạm dừng.

2

Bạn có thể cố gắng thêm một minh bạch View ở vị trí desidered sử dụng WindowManager (theo this chẳng hạn). Bằng cách này, bạn sẽ chặn bất kỳ sự kiện nhấn nào từ người dùng.

Hãy chắc chắn để thiết lập cờ đúng/loại, bởi vì bạn cần phải che phủ các thanh hệ thống:

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

Trước đó tôi đã cố gắng thêm chế độ xem theo cách bạn đã mô tả nhưng chế độ xem đó không xuất hiện trên thanh hệ thống. –

+0

@NareshSharma Bạn đã thử với TYPE_SYSTEM_OVERLAY chưa? – bonnyz

+0

Không hoạt động với cờ đó. –

3

Bí quyết là để thêm giao diện tùy chỉnh trong suốt phủ lên trên thanh hệ thống, mà cách tất cả tương tác của người dùng như chạm, kéo sẽ được tiêu thụ theo chế độ xem tùy chỉnh.

Dưới đây là một mã làm việc:

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

Tuỳ chỉnh 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; 
     } 
    } 

Bản thân tôi đã thực hiện tính năng khóa để ứng dụng của tôi mặc dù tôi đã tách ra các tính năng khóa vào một ứng dụng khác nhau vì nhiều lý do . Bạn có thể yêu cầu thêm thông tin và tôi sẽ đặt chúng ở đây nếu cần.

Các vấn đề liên quan