Example usage for android.provider Settings canDrawOverlays

List of usage examples for android.provider Settings canDrawOverlays

Introduction

In this page you can find the example usage for android.provider Settings canDrawOverlays.

Prototype

public static boolean canDrawOverlays(Context context) 

Source Link

Document

Checks if the specified context can draw on top of other apps.

Usage

From source file:com.appsimobile.appsii.HotspotHelperImpl.java

@Override
public void addHotspots() throws PermissionDeniedException {
    Log.d(TAG, "addHotspots() called with: " + "");
    try {/*from w  w w . j  ava 2s .co m*/
        removeHotspots();
        mHotspotsActive = true;
        if (mHotspotItems != null) {
            int count = mHotspotItems.size();
            SharedPreferences prefs = mSharedPreferences;
            for (int i = 0; i < count; i++) {
                HotspotItem conf = mHotspotItems.get(i);

                HotspotContainerHelper hotspotContainerHelper = mSidebarHotspots.get(conf.mId);
                boolean isAdded = hotspotContainerHelper != null;
                if (!isAdded) {
                    hotspotContainerHelper = createSidebarHotspot();
                }
                hotspotContainerHelper.bind(conf);

                mSidebarHotspots.put(conf.mId, hotspotContainerHelper);

                if (!isAdded) {
                    WindowManager.LayoutParams lp = configureHotspot(hotspotContainerHelper, conf, prefs);
                    try {
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
                                && !Settings.canDrawOverlays(mContext)) {

                            throw new PermissionDeniedException(Manifest.permission.SYSTEM_ALERT_WINDOW);
                        }

                        mWindowManager.addView(hotspotContainerHelper.mHotspotParent, lp);
                    } catch (PermissionDeniedException e) {
                        throw e;
                    } catch (Exception e) {
                        Log.w("HotspotHelperImpl", "error adding hotspot", e);
                        Crashlytics.logException(e);
                    }
                }
            }
        }
        addScreenWatcher();
    } catch (PermissionDeniedException e) {
        mHotspotsActive = false;
    }
}

From source file:com.farmerbb.taskbar.service.StartMenuService.java

@TargetApi(Build.VERSION_CODES.M)
@Override/*from  w ww .  j av  a 2 s  . c om*/
public void onCreate() {
    super.onCreate();

    SharedPreferences pref = U.getSharedPreferences(this);
    if (pref.getBoolean("taskbar_active", false) || LauncherHelper.getInstance().isOnHomeScreen()) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || Settings.canDrawOverlays(this))
            drawStartMenu();
        else {
            pref.edit().putBoolean("taskbar_active", false).apply();

            stopSelf();
        }
    } else
        stopSelf();
}

From source file:com.crea_si.eviacam.service.SplashActivity.java

@Override
@TargetApi(23)/*from  ww  w . j  a va 2s.com*/
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == MANAGE_OVERLAY_PERMISSION_REQUEST) {
        if (!Settings.canDrawOverlays(this)) {
            finish();
        } else {
            checkRequisites();
        }
    }
}

From source file:com.farmerbb.taskbar.service.DashboardService.java

@TargetApi(Build.VERSION_CODES.M)
@Override//w ww .  j a  v  a  2 s . c o  m
public void onCreate() {
    super.onCreate();

    SharedPreferences pref = U.getSharedPreferences(this);
    if (pref.getBoolean("dashboard", false)) {
        if (pref.getBoolean("taskbar_active", false) || LauncherHelper.getInstance().isOnHomeScreen()) {
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || Settings.canDrawOverlays(this))
                drawDashboard();
            else {
                pref.edit().putBoolean("taskbar_active", false).apply();

                stopSelf();
            }
        } else
            stopSelf();
    } else
        stopSelf();
}

From source file:com.rks.musicx.misc.utils.permissionManager.java

public static boolean isSystemAlertGranted(@NonNull Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        boolean result = PermissionChecker.checkCallingOrSelfPermission(context,
                Manifest.permission.SYSTEM_ALERT_WINDOW) == PermissionChecker.PERMISSION_GRANTED;
        if (result || Settings.canDrawOverlays(context)) {
            return true;
        } else {//from  w  w w.ja  v  a  2  s  . c o m
            return false;
        }
    } else {
        return true;
    }
}

From source file:com.farmerbb.taskbar.service.TaskbarService.java

@TargetApi(Build.VERSION_CODES.M)
@Override//from   w  ww  .  j a  va  2  s .co  m
public void onCreate() {
    super.onCreate();

    SharedPreferences pref = U.getSharedPreferences(this);
    if (pref.getBoolean("taskbar_active", false) || LauncherHelper.getInstance().isOnHomeScreen()) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || Settings.canDrawOverlays(this))
            drawTaskbar();
        else {
            pref.edit().putBoolean("taskbar_active", false).apply();

            stopSelf();
        }
    } else
        stopSelf();
}

From source file:arun.com.chromer.webheads.WebHeadService.java

@Override
public void onCreate() {
    super.onCreate();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (!Settings.canDrawOverlays(this)) {
            stopService();//from  ww  w  . j  av a2 s  . c o m
            return;
        }
    }
    springChain2D = SpringChain2D.create(this);
    Trashy.init(this);
    bindToCustomTabSession();
    registerReceivers();
}

From source file:com.farmerbb.secondscreen.service.NotificationService.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override/* w  w  w . j ava  2s.c o  m*/
public void onCreate() {
    // Load preferences
    SharedPreferences prefCurrent = U.getPrefCurrent(this);
    SharedPreferences prefMain = U.getPrefMain(this);

    // Register broadcast receivers for screen on and user present
    final IntentFilter filter1 = new IntentFilter();
    final IntentFilter filter2 = new IntentFilter();

    filter1.addAction(Intent.ACTION_SCREEN_ON);
    filter1.addAction(Intent.ACTION_DREAMING_STARTED);
    filter2.addAction(Intent.ACTION_USER_PRESENT);

    registerReceiver(screenOnReceiver, filter1);
    registerReceiver(userPresentReceiver, filter2);

    DisplayManager manager = (DisplayManager) getSystemService(DISPLAY_SERVICE);
    manager.registerDisplayListener(listener, null);

    // Intent to launch MainActivity when notification is clicked
    Intent mainActivityIntent = new Intent(this, MainActivity.class);
    PendingIntent mainActivityPendingIntent = PendingIntent.getActivity(this, 0, mainActivityIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // Build the notification
    mBuilder = new NotificationCompat.Builder(this).setContentIntent(mainActivityPendingIntent)
            .setSmallIcon(R.drawable.ic_action_dock)
            .setContentTitle(getResources().getString(R.string.notification))
            .setContentText(
                    prefCurrent.getString("profile_name", getResources().getString(R.string.action_new)))
            .setOngoing(true);

    // Set action buttons
    setActionButton(prefMain.getString("notification_action_2", "turn-off"), prefCurrent, 0);
    setActionButton(prefMain.getString("notification_action", "lock-device"), prefCurrent, 1);

    // Respect setting to hide notification
    if (prefMain.getBoolean("hide_notification", false))
        mBuilder.setPriority(Notification.PRIORITY_MIN);

    // Set notification color on Lollipop
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mBuilder.setColor(getResources().getColor(R.color.primary_dark))
                .setVisibility(Notification.VISIBILITY_PUBLIC);
    }

    // Start NotificationService
    startForeground(1, mBuilder.build());

    // Draw system overlay, if needed
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && Settings.canDrawOverlays(this)
            && prefCurrent.getString("rotation_lock_new", "fallback").equals("landscape")) {
        windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
        WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                PixelFormat.TRANSLUCENT);

        params.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;

        view = new View(this);
        windowManager.addView(view, params);
    }
}

From source file:com.wanderfar.expander.Settings.SettingsActivity.java

@TargetApi(Build.VERSION_CODES.M)
private static boolean isSystemAlertPermissionGranted(Context context) {
    return Build.VERSION.SDK_INT < Build.VERSION_CODES.M || Settings.canDrawOverlays(context);
}

From source file:com.tbruyelle.rxpermissions.RxPermissions.java

@TargetApi(Build.VERSION_CODES.M)
private boolean isGranted_(String permission) {
    //special grant permissions
    if (Manifest.permission.SYSTEM_ALERT_WINDOW.equals(permission)) {
        return Settings.canDrawOverlays(mCtx);
    } else if (Manifest.permission.WRITE_SETTINGS.equals(permission)) {
        return Settings.System.canWrite(mCtx);
    }/*from   w  w w . j a v a 2 s .  c  o  m*/
    return mCtx.checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED;
}