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:org.deviceconnect.android.deviceplugin.host.camera.CameraOverlay.java

/**
 * ??????.//from w w w.  java  2s  .co m
 * @param resultReceiver ????
 */
@TargetApi(23)
private void checkOverlayDrawingCapability(@NonNull final ResultReceiver resultReceiver) {
    if (Settings.canDrawOverlays(mContext)) {
        resultReceiver.send(Activity.RESULT_OK, null);
    } else {
        Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                Uri.parse("package:" + mContext.getPackageName()));
        IntentHandlerActivity.startActivityForResult(mContext, intent, new ResultReceiver(mHandler) {
            @Override
            protected void onReceiveResult(int resultCode, Bundle resultData) {
                if (Settings.canDrawOverlays(mContext)) {
                    resultReceiver.send(Activity.RESULT_OK, null);
                } else {
                    resultReceiver.send(Activity.RESULT_CANCELED, null);
                }
            }
        });
    }
}

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

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

    if (layout != null) {
        try {
            windowManager.removeView(layout);
        } catch (IllegalArgumentException e) {
            /* Gracefully fail */ }

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

            stopSelf();
        }
    }
}

From source file:com.rks.musicx.ui.activities.MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == OVERLAY_REQ) {
        if (Build.VERSION.SDK_INT >= M) {
            if (Settings.canDrawOverlays(this)) {
                Log.d("MainActivity", "Granted");
            } else {
                Extras.getInstance().setWidgetTrack(true);
                Log.d("MainActivity", "Denied or Grant permission Manually");
            }/*www  .j  a va  2 s  .c  o m*/
        }
    }
    if (requestCode == WRITESETTINGS) {
        if (Build.VERSION.SDK_INT >= M) {
            if (!Settings.System.canWrite(this)) {
                Log.d("MainActivity", "Granted");
            } else {
                Extras.getInstance().setSettings(true);
                Log.d("MainActivity", "Denied or Grant permission Manually");
            }
        }
    }
    if (requestCode == EQ) {
        Intent intent = new Intent(AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION);
        if (intent.getAction() != null && Helper.isActivityPresent(MainActivity.this, intent)) {
            if (musicXService == null) {
                return;
            }
            intent.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, musicXService.audioSession());
            intent.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, this.getPackageName());
            intent.putExtra(AudioEffect.EXTRA_CONTENT_TYPE, AudioEffect.CONTENT_TYPE_MUSIC);
            sendBroadcast(intent);
        } else {
            Log.d("MainActivity", "Error");
        }
    }
    if (requestCode == NAV && resultCode == RESULT_OK) {
        intent = data;
    }
}

From source file:com.pluscubed.velociraptor.SettingsActivity.java

private void invalidateStates() {
    boolean permissionGranted = isLocationPermissionGranted();
    enabledLocationImage//from  www  . j a va2s .  c om
            .setImageResource(permissionGranted ? R.drawable.ic_done_green_40dp : R.drawable.ic_cross_red_40dp);
    enableLocationButton.setEnabled(!permissionGranted);

    @SuppressLint({ "NewApi", "LocalSuppress" })
    boolean overlayEnabled = Build.VERSION.SDK_INT < Build.VERSION_CODES.M || Settings.canDrawOverlays(this);
    enabledFloatingImage
            .setImageResource(overlayEnabled ? R.drawable.ic_done_green_40dp : R.drawable.ic_cross_red_40dp);
    enableFloatingButton.setEnabled(!overlayEnabled);

    boolean serviceEnabled = Utils.isAccessibilityServiceEnabled(this, AppDetectionService.class);
    enabledServiceImage.setVisibility(serviceEnabled ? View.VISIBLE : View.GONE);
    enableServiceButton.setVisibility(serviceEnabled ? View.GONE : View.VISIBLE);

    String constant = getString(PrefUtils.getUseMetric(this) ? R.string.kmph : R.string.mph,
            String.valueOf(PrefUtils.getSpeedingConstant(this)));
    String percent = getString(R.string.percent, String.valueOf(PrefUtils.getSpeedingPercent(this)));
    String mode = PrefUtils.getToleranceMode(this) ? "+" : getString(R.string.or);
    String overview = getString(R.string.tolerance_desc, percent, mode, constant);
    toleranceOverview.setText(overview);

    updateAppDetectionEnabled(PrefUtils.isAutoDisplayEnabled(this));
    androidAutoSwitch.setEnabled(serviceEnabled);

    if (permissionGranted && overlayEnabled) {
        enableService(true);
    }
}

From source file:com.pluscubed.velociraptor.settings.SettingsActivity.java

private void invalidateStates() {
    boolean permissionGranted = Utils.isLocationPermissionGranted(this);
    enabledLocationImage/*w  ww . j  av  a  2  s  .c o m*/
            .setImageResource(permissionGranted ? R.drawable.ic_done_green_40dp : R.drawable.ic_cross_red_40dp);
    enableLocationButton.setEnabled(!permissionGranted);

    @SuppressLint({ "NewApi", "LocalSuppress" })
    boolean overlayEnabled = Build.VERSION.SDK_INT < Build.VERSION_CODES.M || Settings.canDrawOverlays(this);
    enabledFloatingImage
            .setImageResource(overlayEnabled ? R.drawable.ic_done_green_40dp : R.drawable.ic_cross_red_40dp);
    enableFloatingButton.setEnabled(!overlayEnabled);

    updateAppDetectionOptionStates();

    String constant = getString(PrefUtils.getUseMetric(this) ? R.string.kmph : R.string.mph,
            String.valueOf(PrefUtils.getSpeedingConstant(this)));
    String percent = getString(R.string.percent, String.valueOf(PrefUtils.getSpeedingPercent(this)));
    String mode = PrefUtils.getToleranceMode(this) ? "+" : getString(R.string.or);
    String overview = getString(R.string.tolerance_desc, percent, mode, constant);
    toleranceOverview.setText(overview);

    String limitSizePercent = getString(R.string.percent,
            String.valueOf((int) (PrefUtils.getSpeedLimitSize(this) * 100)));
    String speedLimitSize = getString(R.string.size_limit_overview, limitSizePercent);
    String speedometerSizePercent = getString(R.string.percent,
            String.valueOf((int) (PrefUtils.getSpeedometerSize(this) * 100)));
    String speedometerSize = getString(R.string.size_speedometer_overview, speedometerSizePercent);
    sizeOverview.setText(speedLimitSize + "\n" + speedometerSize);

    opacityOverview.setText(getString(R.string.percent, String.valueOf(PrefUtils.getOpacity(this))));

    if (permissionGranted && overlayEnabled) {
        enableService(true);
    }
}

From source file:com.pluscubed.velociraptor.SettingsActivity.java

private boolean isServiceReady() {
    boolean permissionGranted = isLocationPermissionGranted();
    @SuppressLint({ "NewApi", "LocalSuppress" })
    boolean overlayEnabled = Build.VERSION.SDK_INT < Build.VERSION_CODES.M || Settings.canDrawOverlays(this);
    return permissionGranted && overlayEnabled;
}

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

@TargetApi(Build.VERSION_CODES.M)
@Override/*from   ww  w .  j  ava  2 s.  c  om*/
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    if (layout != null) {
        try {
            windowManager.removeView(layout);
        } catch (IllegalArgumentException e) {
            /* Gracefully fail */ }

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

            stopSelf();
        }
    }
}

From source file:apps.junkuvo.alertapptowalksafely.MainActivity.java

private boolean checkOverlayPermission() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        /** check if we already  have permission to draw over other apps */
        return Settings.canDrawOverlays(this);
    }//w w  w . j  a  v  a2s.  c  om
    return true;
}

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

@TargetApi(Build.VERSION_CODES.M)
@Override/*www.  j  ava  2s  . com*/
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    if (layout != null) {
        try {
            windowManager.removeView(layout);
        } catch (IllegalArgumentException e) {
            /* Gracefully fail */ }

        currentTaskbarPosition = 0;

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

            stopSelf();
        }
    }
}