Java Code Examples for android.provider.Settings#ACTION_MANAGE_OVERLAY_PERMISSION

The following examples show how to use android.provider.Settings#ACTION_MANAGE_OVERLAY_PERMISSION . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SweetToast.java    From SweetTips with Apache License 2.0 13 votes vote down vote up
/**
     * 利用队列{@link SweetToastManager#queue}中正在展示的SweetToast实例,继续展示当前实例的内容
     */
    public void showByPrevious(){
        try {
            if (Build.VERSION.SDK_INT >= 23) {
                //Android6.0以上,需要动态声明权限
                if(mContentView!=null && !Settings.canDrawOverlays(mContentView.getContext().getApplicationContext())) {
                    //用户还未允许该权限
                    Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
                    mContentView.getContext().startActivity(intent);
                    return;
                } else if(mContentView!=null) {
                    //用户已经允许该权限
                    SweetToastManager.showByPrevious(this);
                }
            } else {
                //Android6.0以下,不用动态声明权限
                if (mContentView!=null) {
                    SweetToastManager.showByPrevious(this);
                }
            }
//            SweetToastManager.showByPrevious(this);
        }catch (Exception e){
            Log.e("幻海流心","e:"+e.getLocalizedMessage());
        }
    }
 
Example 2
Source File: CapabilityUtil.java    From DeviceConnect-Android with MIT License 11 votes vote down vote up
/**
 * オーバーレイ表示のパーミッションを確認します.
 *
 * @param context コンテキスト
 * @param handler ハンドラー
 * @param resultReceiver 確認を受けるレシーバ
 */
@TargetApi(23)
private static void checkOverlayDrawingCapability(final Context context, final Handler handler, final ResultReceiver resultReceiver) {
    if (Settings.canDrawOverlays(context)) {
        resultReceiver.send(Activity.RESULT_OK, null);
    } else {
        Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                Uri.parse("package:" + context.getPackageName()));
        IntentHandlerActivity.startActivityForResult(context, intent, new ResultReceiver(handler) {
            @Override
            protected void onReceiveResult(int resultCode, Bundle resultData) {
                if (Settings.canDrawOverlays(context)) {
                    resultReceiver.send(Activity.RESULT_OK, null);
                } else {
                    resultReceiver.send(Activity.RESULT_CANCELED, null);
                }
            }
        });
    }
}
 
Example 3
Source File: SweetToast.java    From SweetTips with Apache License 2.0 6 votes vote down vote up
/**
     * 清空队列{@link SweetToastManager#queue}中已经存在的SweetToast实例,直接展示当前实例的内容
     */
    public void showImmediate(){
        try {
            if (Build.VERSION.SDK_INT >= 23) {
                //Android6.0以上,需要动态声明权限
                if(mContentView!=null && !Settings.canDrawOverlays(mContentView.getContext().getApplicationContext())) {
                    //用户还未允许该权限
                    Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
                    mContentView.getContext().startActivity(intent);
                    return;
                } else if(mContentView!=null) {
                    //用户已经允许该权限
                    SweetToastManager.showImmediate(this);
                }
            } else {
                //Android6.0以下,不用动态声明权限
                if (mContentView!=null) {
                    SweetToastManager.showImmediate(this);
                }
            }
//            SweetToastManager.showImmediate(this);
        }catch (Exception e){
            Log.e("幻海流心","e:"+e.getLocalizedMessage());
        }
    }
 
Example 4
Source File: SweetToast.java    From SweetTips with Apache License 2.0 6 votes vote down vote up
/**
     * 将当前实例添加到队列{@link SweetToastManager#queue}中,若队列为空,则加入队列后直接进行展示
     */
    public void show(){
        try {
            if (Build.VERSION.SDK_INT >= 23) {
                //Android6.0以上,需要动态声明权限
                if(mContentView!=null && !Settings.canDrawOverlays(mContentView.getContext().getApplicationContext())) {
                    //用户还未允许该权限
                    Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
                    mContentView.getContext().startActivity(intent);
                    return;
                } else if(mContentView!=null) {
                    //用户已经允许该权限
                    SweetToastManager.show(this);
                }
            } else {
                //Android6.0以下,不用动态声明权限
                if (mContentView!=null) {
                    SweetToastManager.show(this);
                }
            }
//            SweetToastManager.show(this);
        }catch (Exception e){
            Log.e("幻海流心","e:"+e.getLocalizedMessage());
        }
    }
 
Example 5
Source File: ViewInspectorAspect.java    From ViewInspector with Apache License 2.0 6 votes vote down vote up
@Around("activityOnCreatedCall()")
public Object injectViewInspector(ProceedingJoinPoint joinPoint) throws Throwable {
  Log.d(ViewInspector.TAG, "injectViewInspector");
  Context context = (Context) joinPoint.getThis();

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    if (Settings.canDrawOverlays(context)) {
      mViewInspector.onCreate(context);
      isRestarting = false;
    } else {
      isRequestingOverlayPermission = true;
      Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
      ((Activity) context).startActivityForResult(intent, OVERLAY_PERMISSION_CALL);
    }
  } else {
    mViewInspector.onCreate(context);
  }

  return joinPoint.proceed();
}
 
Example 6
Source File: TinyDancerBuilder.java    From TinyDancer with MIT License 6 votes vote down vote up
/**
 * request overlay permission when api >= 23
 * @param context
 * @return
 */
private boolean overlayPermRequest(Context context) {
    boolean permNeeded = false;
    if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
    {
        if (!Settings.canDrawOverlays(context))
        {
            Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                    Uri.parse("package:" + context.getPackageName()));
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent);
            permNeeded = true;
        }
    }
    return permNeeded;
}
 
Example 7
Source File: PermissionReqFragment.java    From pandora with Apache License 2.0 6 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (code == requestCode) {
        if (resultCode == Activity.RESULT_OK) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                if (!Settings.canDrawOverlays(getContext())) {
                    try {
                        Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
                        intent.setData(Uri.parse("package:" + getContext().getPackageName()));
                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        getActivity().startActivity(intent);
                    } catch (ActivityNotFoundException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
        getActivity().finish();
    }
}
 
Example 8
Source File: ChooseActivity.java    From KSYMediaPlayer_Android with Apache License 2.0 6 votes vote down vote up
private void checkPermission() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.canDrawOverlays(this)) {
        Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                Uri.parse("package:" + getPackageName()));
        startActivityForResult(intent, OVERLAY_PERMISSION_RESULT_CODE);
    }
}
 
Example 9
Source File: MainActivity.java    From loco-answers with GNU General Public License v3.0 5 votes vote down vote up
private void giveOverlayPermission() {
    //&& !SearchSettings.canDrawOverlays(this)
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));
        startActivityForResult(intent, Constant.CODE_DRAW_OVER_OTHER_APP_PERMISSION);
    } else {
        mOverlayPermmissionBtn.setBackgroundColor(getResources().getColor(android.R.color.holo_green_dark));
        Toast.makeText(this, "You do not need it", Toast.LENGTH_SHORT).show();
    }
}
 
Example 10
Source File: FloatingCodecOpenShortCutActivity.java    From text_converter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreate(Bundle state) {
    super.onCreate(state);
    if (!Premium.isPremium(this)) {
        finish();
        return;
    }
    if (android.os.Build.VERSION.SDK_INT >= 23 && !Settings.canDrawOverlays(this)) {
        Uri uri = Uri.parse("package:" + getPackageName());
        Intent activity = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, uri);
        startActivityForResult(activity, REQUEST_CODE_WINDOW_OVERLAY_PERMISSION);
    } else {
        onSuccess();
    }
}
 
Example 11
Source File: HiddenCameraUtils.java    From android-hidden-camera with Apache License 2.0 5 votes vote down vote up
/**
 * This will open settings screen to allow the "Draw over other apps" permission to the application.
 *
 * @param context instance of caller.
 */
public static void openDrawOverPermissionSetting(Context context) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return;

    Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);
}
 
Example 12
Source File: ScrollingActivity.java    From Android-TopScrollHelper with Apache License 2.0 5 votes vote down vote up
public void initTopScrollHelper() {
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (!Settings.canDrawOverlays(this)) {
            Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                    Uri.parse("package:" + getPackageName()));
            startActivityForResult(intent, OVERLAY_PERMISSION_REQ_CODE);
            return;
        }
    }

    TopScrollHelper.getInstance(getApplicationContext()).addTargetScrollView(mNestedScrollView);

}
 
Example 13
Source File: MSettingPage.java    From AndPermission with Apache License 2.0 5 votes vote down vote up
private static Intent defaultApi(Context context) {
    Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
    intent.setData(Uri.fromParts("package", context.getPackageName(), null));
    if (hasActivity(context, intent)) return intent;

    return appDetailsApi(context);
}
 
Example 14
Source File: SettingsActivity.java    From CamCov with GNU General Public License v3.0 5 votes vote down vote up
boolean requireOverlayPermission() {
    if (overlayPermissionIsFine()) {
        has_overlay_permission = true;
    } else {
        Log.d(TAG, " requiring OVERLAY permission");
        Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                Uri.parse("package:" + getPackageName()));
        startActivityForResult(intent, REQUEST_CODE_MANAGE_OVERLAY_PERMISSION);
    }
    return !has_overlay_permission;
}
 
Example 15
Source File: MainActivity.java    From debugoverlay with Apache License 2.0 5 votes vote down vote up
private void requestOverlayPermission() {
  if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.M) {
    return;
  }

  Intent myIntent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
  myIntent.setData(Uri.parse("package:" + getPackageName()));
  startActivityForResult(myIntent, APP_PERMISSIONS);
}
 
Example 16
Source File: OverlayPermissionActivity.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
/**
 * オーバーレイの表示設定画面を開きます.
 *
 * Android OS 標準の設定画面になります。
 */
private void requestOverlayPermission() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                Uri.parse("package:" + getPackageName()));
        startActivityForResult(intent, REQUEST_CODE_OVERLAY);
    }
}
 
Example 17
Source File: UETool.java    From UETool with MIT License 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.M)
private void requestPermission(Context context) {
    Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + context.getPackageName()));
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);
}
 
Example 18
Source File: SettingFragment.java    From RelaxFinger with GNU General Public License v2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.M)
public void requestDrawOverLays() {

    try {

        if (!Settings.canDrawOverlays(mActivity)) {
            Toast.makeText(mContext, "悬浮助手需要开启在其他应用上层显示权限!", Toast.LENGTH_SHORT).show();
            Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + mActivity.getPackageName()));
            startActivityForResult(intent, OVERLAY_PERMISSION_REQ_CODE);
        }else {

            activateFloatService();
        }

    }catch (Exception e){

        e.printStackTrace();

        Toast.makeText(mActivity, "没有找到在其他应用上层显示设置界面,请手动开启悬浮窗权限!", Toast.LENGTH_SHORT).show();


    }

}
 
Example 19
Source File: MrReactActivity.java    From react-native-preloader with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (getUseDeveloperSupport() && Build.VERSION.SDK_INT >= 23) {
        // Get permission to show redbox in dev builds.
        if (!Settings.canDrawOverlays(this)) {
            Intent serviceIntent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
            startActivity(serviceIntent);
            FLog.w(ReactConstants.TAG, REDBOX_PERMISSION_MESSAGE);
            Toast.makeText(this, REDBOX_PERMISSION_MESSAGE, Toast.LENGTH_LONG).show();
        }
    }

    mReactRootView = ReactPreLoader.getRootView(getReactInfo());

    if (mReactRootView != null) {
        Log.i(TAG, "use pre-load view");
        MutableContextWrapper contextWrapper = (MutableContextWrapper) mReactRootView.getContext();
        contextWrapper.setBaseContext(this);
        try {
            ViewGroup viewGroup = (ViewGroup) mReactRootView.getParent();
            if (viewGroup != null) {
                viewGroup.removeView(mReactRootView);
            }
        } catch (Exception exception) {
            Log.e(TAG, "getParent error", exception);
        }
    } else {
        Log.i(TAG, "createRootView");
        mReactRootView = createRootView();
        if (mReactRootView != null) {
            mReactRootView.startReactApplication(
                    getReactNativeHost().getReactInstanceManager(),
                    getMainComponentName(),
                    getLaunchOptions());
        }
    }

    setContentView(mReactRootView);

    mDoubleTapReloadRecognizer = new DoubleTapReloadRecognizer();
}
 
Example 20
Source File: WindowActivity.java    From GSYVideoPlayer with Apache License 2.0 4 votes vote down vote up
@RequiresApi(api = 23)
private void requestAlertWindowPermission() {
    Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));
    startActivityForResult(intent, 1);
}