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;
}
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);
}
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;
}
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;
}
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;
}
Aggregations