Java Code Examples for android.provider.Settings#canDrawOverlays()
The following examples show how to use
android.provider.Settings#canDrawOverlays() .
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: MainActivity.java From android-samples with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //Check if the application has draw over other apps permission or not? //This permission is by default available for API<23. But for API > 23 //you have to ask for the permission in runtime. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.canDrawOverlays(this)) { //If the draw over permission is not available open the settings screen //to grant the permission. Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName())); startActivityForResult(intent, CODE_DRAW_OVER_OTHER_APP_PERMISSION); } else { initializeView(); } }
Example 2
Source File: DataInspectorAspect.java From DataInspector with Apache License 2.0 | 6 votes |
@Around("activityOnCreatedCall()") public Object injectDataInspector(ProceedingJoinPoint joinPoint) throws Throwable { Log.d(DataInspector.TAG, "injectDataInspector"); Context context = (Context) joinPoint.getThis(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Settings.canDrawOverlays(context)) { dataInspector.onCreate(context); isRestarting = false; } else { isRequestingOverlayPermission = true; Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION); ((Activity) context).startActivityForResult(intent, OVERLAY_PERMISSION_CALL); } } else { dataInspector.onCreate(context); } return joinPoint.proceed(); }
Example 3
Source File: DragGridView.java From DragGridView with Apache License 2.0 | 6 votes |
@Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { if (mode == MODE_DRAG) { return false; } this.view = view; this.position = position; this.tempPosition = position; mX = mWindowX - view.getLeft() - this.getLeft(); mY = mWindowY - view.getTop() - this.getTop(); // 如果是Android 6.0 要动态申请权限 if (Build.VERSION.SDK_INT >= 23) { if (Settings.canDrawOverlays(getContext())) { initWindow(); } else { // 跳转到悬浮窗权限管理界面 Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION); getContext().startActivity(intent); } } else { // 如果小于Android 6.0 则直接执行 initWindow(); } return true; }
Example 4
Source File: PIPVideoPlayer.java From dingo with GNU General Public License v3.0 | 6 votes |
public static void open(Context context, Uri url){ // Check if Android M or higher if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.canDrawOverlays(context)) { new AlertDialog.Builder(context) .setTitle("Need Permissions") .setMessage("dingo needs \"Draw over other apps\" permission to play videos") .setCancelable(false) .setPositiveButton("Give Permission", (dialog, which) -> ContextCompat.startActivity( context, new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + context.getPackageName())) ,null)) .show(); }else{ if(isMyServiceRunning(context, PIPVideoPlayerService.class)){ PIPVideoPlayerService.load(url.toString()); }else{ final Intent serviceStarterIntent = new Intent(context, PIPVideoPlayerService.class); serviceStarterIntent.setData(url); ContextCompat.startForegroundService(context, serviceStarterIntent); } } }
Example 5
Source File: TinyDancerBuilder.java From TinyDancer with MIT License | 6 votes |
/** * 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 6
Source File: CreateShortcutActivity.java From text_converter with GNU General Public License v3.0 | 6 votes |
public void onCreate(Bundle state) { super.onCreate(state); if (Intent.ACTION_CREATE_SHORTCUT.equals(getIntent().getAction())) { if (Build.VERSION.SDK_INT >= 23 && !Settings.canDrawOverlays(this)) { startActivityForResult( new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName())), REQUEST_CODE_WINDOW_OVERLAY_PERMISSION); } else { onSuccess(); } } else { Log.w(TAG, "CreateShortcutActivity called with unexpected Action " + getIntent().getAction()); onFailure(); } }
Example 7
Source File: SweetToast.java From SweetTips with Apache License 2.0 | 6 votes |
/** * 将当前实例添加到队列{@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 8
Source File: Takt.java From stynico with MIT License | 5 votes |
private boolean hasOverlayPermission() { if (!isOverlayApiDeprecated()) { return true; // permission no required } else { return Settings.canDrawOverlays(app); } }
Example 9
Source File: FloatingStylishCreateShortCutActivity.java From text_converter with GNU General Public License v3.0 | 5 votes |
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_CODE_WINDOW_OVERLAY_PERMISSION) { if (android.os.Build.VERSION.SDK_INT < 23 || Settings.canDrawOverlays(this)) { onSuccess(); } else { onFailure(); } } }
Example 10
Source File: MainActivity.java From floaties with Apache License 2.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.M) @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == PERMISSION_REQUEST_CODE) { if (Settings.canDrawOverlays(this)) { floaty.startService(); } else { Spanned message = Html.fromHtml("Please allow this permission, so <b>Floaties</b> could be drawn."); Toast.makeText(this, message, Toast.LENGTH_LONG).show(); } } }
Example 11
Source File: DebugOverlayController.java From react-native-GPay with MIT License | 5 votes |
private static boolean permissionCheck(Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // Get permission to show debug overlay in dev builds. if (!Settings.canDrawOverlays(context)) { // overlay permission not yet granted return false; } else { return true; } } // on pre-M devices permission needs to be specified in manifest return hasPermission(context, Manifest.permission.SYSTEM_ALERT_WINDOW); }
Example 12
Source File: WindowManagerActivity.java From Android-skin-support with MIT License | 5 votes |
@RequiresApi(api = Build.VERSION_CODES.M) @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == 10) { if (Settings.canDrawOverlays(this)) { startWindowService(); } else { Toast.makeText(WindowManagerActivity.this, "not granted", Toast.LENGTH_SHORT).show(); } } }
Example 13
Source File: KcaFleetCheckPopupService.java From kcanotify_h5-master with GNU General Public License v3.0 | 5 votes |
@Override public int onStartCommand(Intent intent, int flags, int startId) { Log.e("KCA-MPS", "onStartCommand"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.canDrawOverlays(getApplicationContext())) { // Can not draw overlays: pass stopSelf(); } else if (intent != null && intent.getAction() != null) { if (intent.getAction().equals(FCHK_SHOW_ACTION)) { portdeckdata = dbHelper.getJsonArrayValue(DB_KEY_DECKPORT); if (portdeckdata != null) { deck_cnt = portdeckdata.size(); setFchkFleetBtnColor(recent_no, deck_cnt); setFchkFuncBtnColor(current_func); setText(); } mView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); popupWidth = mView.getMeasuredWidth(); popupHeight = mView.getMeasuredHeight(); mParams.x = (screenWidth - popupWidth) / 2; mParams.y = (screenHeight - popupHeight) / 2; mManager.updateViewLayout(mView, mParams); } } return super.onStartCommand(intent, flags, startId); }
Example 14
Source File: ScrollingActivity.java From Android-TopScrollHelper with Apache License 2.0 | 5 votes |
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (requestCode == OVERLAY_PERMISSION_REQ_CODE) { if (!Settings.canDrawOverlays(this)) { TopScrollHelper.getInstance(getApplicationContext()).addTargetScrollView(mNestedScrollView); } } } }
Example 15
Source File: MainActivity.java From fuckView with GNU Affero General Public License v3.0 | 5 votes |
@SuppressLint("WorldReadableFiles") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mSettings = PreferenceManager.getDefaultSharedPreferences(this); //Setting the theme if (isDayTheme(this)) { setTheme(R.style.DayTheme); } setContentView(R.layout.activity_main); checkAndCallPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (!Settings.canDrawOverlays(this)) { Toast.makeText(this, R.string.cant_open_popup, Toast.LENGTH_SHORT).show(); startActivity(new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse(String.format("package:%s", getPackageName())))); finish(); } } sSharedPreferences = getSharedPreferences("data", Context.MODE_WORLD_READABLE); dealWithIntent(); keepAlive(); //If it is the first time to run... if (FirstRun.isFirstRun(this, "app")) { setFragmentWithoutBack(new WelcomeFragment()); //else if there's no rule... } else { setFragmentWithoutBack(new MainFragment()); if (isModuleActive()) { giveMeFive(); } else { checkModuleActivated(); } } }
Example 16
Source File: PermissionHelper.java From PermissionHelper with Apache License 2.0 | 5 votes |
/** * @return true if {@link android.Manifest.permission#SYSTEM_ALERT_WINDOW} is granted */ public static boolean isSystemAlertGranted(@NonNull Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { return Settings.canDrawOverlays(context); } return true; }
Example 17
Source File: Compatibility.java From linphone-android with GNU General Public License v3.0 | 4 votes |
public static boolean canDrawOverlays(Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { return Settings.canDrawOverlays(context); } return true; }
Example 18
Source File: KcaLandAirBasePopupService.java From kcanotify with GNU General Public License v3.0 | 4 votes |
@Override public void onCreate() { super.onCreate(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.canDrawOverlays(getApplicationContext())) { // Can not draw overlays: pass stopSelf(); } else { active = true; clickcount = 0; dbHelper = new KcaDBHelper(getApplicationContext(), null, KCANOTIFY_DB_VERSION); deckInfoCalc = new KcaDeckInfo(getApplicationContext(), getBaseContext()); KcaApiData.setDBHelper(dbHelper); setDefaultGameData(); LayoutInflater mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); mView = mInflater.inflate(R.layout.view_labinfo_view, null); itemView = mInflater.inflate(R.layout.view_battleview_items, null); mView.setOnTouchListener(mViewTouchListener); mView.findViewById(R.id.view_lab_head).setOnTouchListener(mViewTouchListener); mView.setVisibility(View.GONE); ((TextView) mView.findViewById(R.id.view_lab_title)).setText(getStringWithLocale(R.string.viewmenu_airbase_title)); mView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); popupWidth = mView.getMeasuredWidth(); popupHeight = mView.getMeasuredHeight(); // Button (Fairy) Settings mParams = new WindowManager.LayoutParams( WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, getWindowLayoutType(), WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT); mParams.gravity = Gravity.TOP | Gravity.START; Display display = ((WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); Point size = new Point(); display.getSize(size); screenWidth = size.x; screenHeight = size.y; Log.e("KCA", "w/h: " + String.valueOf(screenWidth) + " " + String.valueOf(screenHeight)); mParams.x = (screenWidth - popupWidth) / 2; mParams.y = (screenHeight - popupHeight) / 2; mManager = (WindowManager) getSystemService(WINDOW_SERVICE); mManager.addView(mView, mParams); itemViewParams = new WindowManager.LayoutParams( WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, getWindowLayoutType(), WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT); } }
Example 19
Source File: MrReactActivity.java From react-native-preloader with Apache License 2.0 | 4 votes |
@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: PermissionsHelper.java From FastAccess with GNU General Public License v3.0 | 4 votes |
@TargetApi(Build.VERSION_CODES.M) public static boolean isSystemAlertGranted(@NonNull Context context) { return Build.VERSION.SDK_INT < Build.VERSION_CODES.M || Settings.canDrawOverlays(context); }