Search in sources :

Example 31 with RequiresPermission

use of androidx.annotation.RequiresPermission in project Moneycim by volkansahin45.

the class CameraSource method start.

/**
 * Opens the camera and starts sending preview frames to the underlying detector.  The preview
 * frames are not displayed.
 *
 * @throws IOException if the camera's preview texture or display could not be initialized
 */
@RequiresPermission(Manifest.permission.CAMERA)
public CameraSource start() throws IOException {
    synchronized (mCameraLock) {
        if (mCamera != null) {
            return this;
        }
        mCamera = createCamera();
        // SurfaceTexture was introduced in Honeycomb (11), so if we are running and
        // old version of Android. fall back to use SurfaceView.
        SurfaceTexture mDummySurfaceTexture = new SurfaceTexture(DUMMY_TEXTURE_NAME);
        mCamera.setPreviewTexture(mDummySurfaceTexture);
        mCamera.startPreview();
        mProcessingThread = new Thread(mFrameProcessor);
        mFrameProcessor.setActive(true);
        mProcessingThread.start();
    }
    return this;
}
Also used : SurfaceTexture(android.graphics.SurfaceTexture) RequiresPermission(androidx.annotation.RequiresPermission)

Example 32 with RequiresPermission

use of androidx.annotation.RequiresPermission in project LshUtils by SenhLinsh.

the class PowerHelperEx method keepScreenOn.

@RequiresPermission(Manifest.permission.WAKE_LOCK)
public void keepScreenOn(long timeOut) {
    PowerManager powerManager = (PowerManager) getContext().getSystemService(Service.POWER_SERVICE);
    mWakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, getClass().getSimpleName());
    mWakeLock.setReferenceCounted(false);
    mWakeLock.acquire(timeOut);
}
Also used : PowerManager(android.os.PowerManager) RequiresPermission(androidx.annotation.RequiresPermission)

Example 33 with RequiresPermission

use of androidx.annotation.RequiresPermission in project speechutils by Kaljurand.

the class SpeechAudioRecord method create.

@RequiresPermission(RECORD_AUDIO)
public static AudioRecord create(int audioSource, int sampleRateInHz, int channelConfig, int audioFormat, int bufferSizeInBytes, boolean noise, boolean gain, boolean echo) throws IllegalArgumentException, SecurityException {
    // TODO: setPrivacySensitive(true) if API 30+
    AudioRecord audioRecord = new AudioRecord.Builder().setAudioSource(audioSource).setAudioFormat(new AudioFormat.Builder().setEncoding(audioFormat).setSampleRate(sampleRateInHz).setChannelMask(channelConfig).build()).setBufferSizeInBytes(bufferSizeInBytes).build();
    int audioSessionId = audioRecord.getAudioSessionId();
    if (noise) {
        if (NoiseSuppressor.create(audioSessionId) == null) {
            Log.i("NoiseSuppressor: failed");
        } else {
            Log.i("NoiseSuppressor: ON");
        }
    } else {
        Log.i("NoiseSuppressor: OFF");
    }
    if (gain) {
        if (AutomaticGainControl.create(audioSessionId) == null) {
            Log.i("AutomaticGainControl: failed");
        } else {
            Log.i("AutomaticGainControl: ON");
        }
    } else {
        Log.i("AutomaticGainControl: OFF");
    }
    if (echo) {
        if (AcousticEchoCanceler.create(audioSessionId) == null) {
            Log.i("AcousticEchoCanceler: failed");
        } else {
            Log.i("AcousticEchoCanceler: ON");
        }
    } else {
        Log.i("AcousticEchoCanceler: OFF");
    }
    return audioRecord;
}
Also used : AudioRecord(android.media.AudioRecord) AudioFormat(android.media.AudioFormat) RequiresPermission(androidx.annotation.RequiresPermission)

Example 34 with RequiresPermission

use of androidx.annotation.RequiresPermission in project AndroidUtilCode by Blankj.

the class NetworkUtils method isWifiConnected.

/**
 * Return whether wifi is connected.
 * <p>Must hold {@code <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />}</p>
 *
 * @return {@code true}: connected<br>{@code false}: disconnected
 */
@RequiresPermission(ACCESS_NETWORK_STATE)
public static boolean isWifiConnected() {
    ConnectivityManager cm = (ConnectivityManager) Utils.getApp().getSystemService(Context.CONNECTIVITY_SERVICE);
    if (cm == null)
        return false;
    NetworkInfo ni = cm.getActiveNetworkInfo();
    return ni != null && ni.getType() == ConnectivityManager.TYPE_WIFI;
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager) RequiresPermission(androidx.annotation.RequiresPermission)

Example 35 with RequiresPermission

use of androidx.annotation.RequiresPermission in project AndroidUtilCode by Blankj.

the class NetworkUtils method getWifiScanResult.

@RequiresPermission(allOf = { ACCESS_WIFI_STATE, ACCESS_COARSE_LOCATION })
public static WifiScanResults getWifiScanResult() {
    WifiScanResults result = new WifiScanResults();
    if (!getWifiEnabled())
        return result;
    @SuppressLint("WifiManagerLeak") WifiManager wm = (WifiManager) Utils.getApp().getSystemService(WIFI_SERVICE);
    // noinspection ConstantConditions
    List<ScanResult> results = wm.getScanResults();
    if (results != null) {
        result.setAllResults(results);
    }
    return result;
}
Also used : WifiManager(android.net.wifi.WifiManager) ScanResult(android.net.wifi.ScanResult) SuppressLint(android.annotation.SuppressLint) RequiresPermission(androidx.annotation.RequiresPermission)

Aggregations

RequiresPermission (androidx.annotation.RequiresPermission)43 SuppressLint (android.annotation.SuppressLint)11 WifiManager (android.net.wifi.WifiManager)5 TelephonyManager (android.telephony.TelephonyManager)4 ActivityManager (android.app.ActivityManager)3 Intent (android.content.Intent)3 SurfaceTexture (android.graphics.SurfaceTexture)3 Vibrator (android.os.Vibrator)3 Size (com.google.android.gms.common.images.Size)3 TargetApi (android.annotation.TargetApi)2 ConnectivityManager (android.net.ConnectivityManager)2 NetworkInfo (android.net.NetworkInfo)2 Bundle (android.os.Bundle)2 PowerManager (android.os.PowerManager)2 SpannableString (android.text.SpannableString)2 Rational (android.util.Rational)2 Size (android.util.Size)2 SurfaceView (android.view.SurfaceView)2 CameraSelector (androidx.camera.core.CameraSelector)2 NumberParseException (com.google.i18n.phonenumbers.NumberParseException)2