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 . These examples are extracted from open source projects. 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 Project: SweetTips   File: SweetToast.java    License: 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 Project: DeviceConnect-Android   File: CapabilityUtil.java    License: 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 Project: TinyDancer   File: TinyDancerBuilder.java    License: 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 4
Source Project: pandora   File: PermissionReqFragment.java    License: 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 5
@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 Project: SweetTips   File: SweetToast.java    License: 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 7
Source Project: SweetTips   File: SweetToast.java    License: 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 8
/**
 * オーバーレイの表示設定画面を開きます.
 *
 * 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 9
Source Project: debugoverlay   File: MainActivity.java    License: 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 10
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 11
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 12
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 13
Source Project: AndPermission   File: MSettingPage.java    License: 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
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 15
/**
 * 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 16
@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 17
Source Project: GSYVideoPlayer   File: WindowActivity.java    License: 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);
}
 
Example 18
@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 19
@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 20
Source Project: UETool   File: UETool.java    License: 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);
}