Java Code Examples for android.support.annotation.RequiresPermission

The following examples show how to use android.support.annotation.RequiresPermission. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: VehicleInfoOCR   Source File: CameraSource.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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
 */
@SuppressLint("MissingPermission")
@RequiresPermission(Manifest.permission.CAMERA)
public synchronized CameraSource start() throws IOException {
    if (camera != null) {
        return this;
    }

    camera = createCamera();
    dummySurfaceTexture = new SurfaceTexture(DUMMY_TEXTURE_NAME);
    camera.setPreviewTexture(dummySurfaceTexture);
    usingSurfaceTexture = true;
    camera.startPreview();

    processingThread = new Thread(processingRunnable);
    processingRunnable.setActive(true);
    processingThread.start();
    return this;
}
 
Example 2
@RequiresPermission(Manifest.permission.CAMERA)
private void startIfReady() throws IOException, SecurityException {
    if (mStartRequested && mSurfaceAvailable) {
        mCameraSource.start(mSurfaceView.getHolder());
        if (mOverlay != null) {
            Size size = mCameraSource.getPreviewSize();
            int min = Math.min(size.getWidth(), size.getHeight());
            int max = Math.max(size.getWidth(), size.getHeight());
            if (isPortraitMode()) {
                // Swap width and height sizes when in portrait, since it will be rotated by
                // 90 degrees
                mOverlay.setCameraInfo(min, max, mCameraSource.getCameraFacing());
            } else {
                mOverlay.setCameraInfo(max, min, mCameraSource.getCameraFacing());
            }
            mOverlay.clear();
        }
        mStartRequested = false;
    }
}
 
Example 3
Source Project: Android-utils   Source File: DeviceUtils.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressLint("HardwareIds")
@RequiresPermission(READ_PHONE_STATE)
public static String getDeviceId() {
    TelephonyManager tm =
            (TelephonyManager) UtilsApp.getApp().getSystemService(Context.TELEPHONY_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        //noinspection ConstantConditions
        String imei = tm.getImei();
        if (!TextUtils.isEmpty(imei)) return imei;
        String meid = tm.getMeid();
        return TextUtils.isEmpty(meid) ? "" : meid;

    }
    //noinspection ConstantConditions
    return tm.getDeviceId();
}
 
Example 4
Source Project: Android-utils   Source File: DeviceUtils.java    License: Apache License 2.0 6 votes vote down vote up
@RequiresPermission(allOf = {ACCESS_WIFI_STATE, INTERNET})
public static String getMacAddress(final String... excepts) {
    String macAddress = getMacAddressByWifiInfo();
    if (isAddressNotInExcepts(macAddress, excepts)) {
        return macAddress;
    }
    macAddress = getMacAddressByNetworkInterface();
    if (isAddressNotInExcepts(macAddress, excepts)) {
        return macAddress;
    }
    macAddress = getMacAddressByInetAddress();
    if (isAddressNotInExcepts(macAddress, excepts)) {
        return macAddress;
    }
    macAddress = getMacAddressByFile();
    if (isAddressNotInExcepts(macAddress, excepts)) {
        return macAddress;
    }
    return "";
}
 
Example 5
Source Project: Android-VMLib   Source File: Downloader.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Download file of given url.
 *
 * @param url              the url
 * @param filePath         the file path to save file
 * @param fileName         the file name of downloaded file
 * @param downloadListener the download state callback
 */
@RequiresPermission(allOf = {ACCESS_WIFI_STATE, INTERNET, ACCESS_NETWORK_STATE, WRITE_EXTERNAL_STORAGE})
public void download(@NonNull String url, @NonNull String filePath, @Nullable String fileName, @Nullable DownloadListener downloadListener) {
    this.downloadListener = downloadListener;
    this.url = url;
    this.filePath = filePath;
    if (fileName == null) L.w("The parameter 'fileName' was null, timestamp will be used.");
    this.fileName = fileName == null ? String.valueOf(System.currentTimeMillis()) : fileName;

    if (!NetworkUtils.isConnected()) {
        notifyDownloadError(ERROR_CODE_NETWORK_UNAVAILABLE);
    } else {
        if (onlyWifi) {
            checkWifiAvailable();
        } else {
            doDownload();
        }
    }
}
 
Example 6
Source Project: ETHWallet   Source File: CameraSource.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Opens the camera and starts sending preview frames to the underlying detector.  The supplied
 * surface holder is used for the preview so frames can be displayed to the user.
 *
 * @param surfaceHolder the surface holder to use for the preview frames
 * @throws IOException if the supplied surface holder could not be used as the preview display
 */
@RequiresPermission(Manifest.permission.CAMERA)
public CameraSource start(SurfaceHolder surfaceHolder) throws IOException {
    synchronized (mCameraLock) {
        if (mCamera != null) {
            return this;
        }

        mCamera = createCamera();
        mCamera.setPreviewDisplay(surfaceHolder);
        mCamera.startPreview();

        mProcessingThread = new Thread(mFrameProcessor);
        mFrameProcessor.setActive(true);
        mProcessingThread.start();
    }
    return this;
}
 
Example 7
Source Project: mobikul-standalone-pos   Source File: CameraSource.java    License: MIT License 6 votes vote down vote up
/**
 * Opens the camera and starts sending preview frames to the underlying detector.  The supplied
 * surface holder is used for the preview so frames can be displayed to the user.
 *
 * @param surfaceHolder the surface holder to use for the preview frames
 * @throws IOException if the supplied surface holder could not be used as the preview display
 */
@RequiresPermission(Manifest.permission.CAMERA)
public CameraSource start(SurfaceHolder surfaceHolder) throws IOException {
    synchronized (mCameraLock) {
        if (mCamera != null) {
            return this;
        }

        mCamera = createCamera();
        mCamera.setPreviewDisplay(surfaceHolder);
        mCamera.startPreview();

        mProcessingThread = new Thread(mFrameProcessor);
        mFrameProcessor.setActive(true);
        mProcessingThread.start();
    }
    return this;
}
 
Example 8
Source Project: Barcode-Reader   Source File: CameraSourcePreview.java    License: Apache License 2.0 6 votes vote down vote up
@RequiresPermission(Manifest.permission.CAMERA)
private void startIfReady() throws IOException, SecurityException {
    if (mStartRequested && mSurfaceAvailable) {
        mCameraSource.start(mSurfaceView.getHolder());
        if (mOverlay != null) {
            Size size = mCameraSource.getPreviewSize();
            int min = Math.min(size.getWidth(), size.getHeight());
            int max = Math.max(size.getWidth(), size.getHeight());
            if (isPortraitMode()) {
                // Swap width and height sizes when in portrait, since it will be rotated by
                // 90 degrees
                mOverlay.setCameraInfo(min, max, mCameraSource.getCameraFacing());
            } else {
                mOverlay.setCameraInfo(max, min, mCameraSource.getCameraFacing());
            }
            mOverlay.clear();
        }
        mStartRequested = false;
    }
}
 
Example 9
Source Project: Barcode-Reader   Source File: CameraSource.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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.
        mDummySurfaceTexture = new SurfaceTexture(DUMMY_TEXTURE_NAME);
        mCamera.setPreviewTexture(mDummySurfaceTexture);
        mCamera.startPreview();

        mProcessingThread = new Thread(mFrameProcessor);
        mFrameProcessor.setActive(true);
        mProcessingThread.start();
    }
    return this;
}
 
Example 10
/**
 * Opens the camera and starts sending preview frames to the underlying detector.  The supplied
 * surface holder is used for the preview so frames can be displayed to the user.
 *
 * @param surfaceHolder the surface holder to use for the preview frames
 * @throws IOException if the supplied surface holder could not be used as the preview display
 */
@RequiresPermission(Manifest.permission.CAMERA)
public CameraSource start(SurfaceHolder surfaceHolder) throws IOException {
    synchronized (mCameraLock) {
        if (mCamera != null) {
            return this;
        }

        mCamera = createCamera();
        mCamera.setPreviewDisplay(surfaceHolder);
        mCamera.startPreview();

        mProcessingThread = new Thread(mFrameProcessor);
        mFrameProcessor.setActive(true);
        mProcessingThread.start();
    }
    return this;
}
 
Example 11
@SuppressLint("MissingPermission")
@RequiresPermission(allOf = {Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION})
public void removeUpdates() {
    if (mLocationManager == null || mLocationListener == null) {
        LogUtil.w(TAG, "Cannot remove updates");

        return;
    }

    LogUtil.d(TAG, "Trying to remove updates...");
    try {
        mLocationManager.removeUpdates(mLocationListener);
    } catch (Exception e) {
        LogUtil.e(TAG, "Exception while trying to remove updates");

        LogUtil.e(TAG, e.getMessage());
        LogUtil.e(TAG, e.toString());

        e.printStackTrace();
    }
}
 
Example 12
/**
 * Opens the camera and starts sending preview frames to the underlying detector.  The supplied
 * texture view is used for the preview so frames can be displayed to the user.
 *
 * @param textureView        the surface holder to use for the preview frames
 * @param displayOrientation the display orientation for a non stretched preview
 * @throws IOException if the supplied texture view could not be used as the preview display
 */
@RequiresPermission(Manifest.permission.CAMERA)
public Camera2Source start(@NonNull AutoFitTextureView textureView, int displayOrientation) throws IOException {
    mDisplayOrientation = displayOrientation;
    if (ContextCompat.checkSelfPermission(mContext, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED) {
        if (cameraStarted) {
            return this;
        }
        cameraStarted = true;
        startBackgroundThread();

        mProcessingThread = new Thread(mFrameProcessor);
        mFrameProcessor.setActive(true);
        mProcessingThread.start();

        mTextureView = textureView;
        if (mTextureView.isAvailable()) {
            setUpCameraOutputs(mTextureView.getWidth(), mTextureView.getHeight());
        }
    }
    return this;
}
 
Example 13
Source Project: ImageLoader   Source File: BigImageView.java    License: Apache License 2.0 6 votes vote down vote up
@RequiresPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)//ojk合规屏蔽
public void saveImageIntoGallery() {
    if (mCurrentImageFile == null) {
        if (mImageSaveCallback != null) {
            mImageSaveCallback.onFail(new IllegalStateException("image not downloaded yet"));
        }

        return;
    }

    try {
        String result = MediaStore.Images.Media.insertImage(getContext().getContentResolver(),
                mCurrentImageFile.getAbsolutePath(), mCurrentImageFile.getName(), "");
        if (mImageSaveCallback != null) {
            if (!TextUtils.isEmpty(result)) {
                mImageSaveCallback.onSuccess(result);
            } else {
                mImageSaveCallback.onFail(new RuntimeException("saveImageIntoGallery fail"));
            }
        }
    } catch (FileNotFoundException e) {
        if (mImageSaveCallback != null) {
            mImageSaveCallback.onFail(e);
        }
    }
}
 
Example 14
Source Project: UnityBluetoothPlugin   Source File: BluetoothPlugin.java    License: Apache License 2.0 6 votes vote down vote up
@RequiresPermission(
        allOf = {"android.permission.BLUETOOTH", "android.permission.BLUETOOTH_ADMIN"}
)
String DisableBluetooth() {
    if(!this.mBtAdapter.isEnabled()) {
        return "You Must Enable The BlueTooth";
    } else {
        if(this.mBtAdapter != null) {
            this.mBtAdapter.cancelDiscovery();
        }

        if(this.mBtAdapter.isEnabled()) {
            this.mBtAdapter.disable();
        }

        return "SUCCESS";
    }
}
 
Example 15
Source Project: OCR-Reader   Source File: CameraSourcePreview.java    License: MIT License 6 votes vote down vote up
@RequiresPermission(Manifest.permission.CAMERA)
private void startIfReady() throws IOException, SecurityException {
    if (mStartRequested && mSurfaceAvailable) {
        mCameraSource.start(mSurfaceView.getHolder());
        if (mOverlay != null) {
            Size size = mCameraSource.getPreviewSize();
            int min = Math.min(size.getWidth(), size.getHeight());
            int max = Math.max(size.getWidth(), size.getHeight());
            if (isPortraitMode()) {
                // Swap width and height sizes when in portrait, since it will be rotated by
                // 90 degrees
                mOverlay.setCameraInfo(min, max, mCameraSource.getCameraFacing());
            } else {
                mOverlay.setCameraInfo(max, min, mCameraSource.getCameraFacing());
            }
            mOverlay.clear();
        }
        mStartRequested = false;
    }
}
 
Example 16
Source Project: MiPushFramework   Source File: LegacyImpl.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
@RequiresPermission(value = Constants.permissions.READ_SETTINGS)
public int checkOp(int op) {
    enforceConnected();
    try {
        return getService().checkOp(op);
    } catch (RemoteException e) {
        throw new RuntimeException(e);
    }
}
 
Example 17
Source Project: Android-utils   Source File: NetworkUtils.java    License: Apache License 2.0 5 votes vote down vote up
@RequiresPermission(INTERNET)
public static boolean isAvailableByPing(String ip) {
    if (ip == null || ip.length() <= 0) {
        ip = "223.5.5.5";// default ping ip
    }
    ShellUtils.CommandResult result = ShellUtils.execCmd(String.format("ping -c 1 %s", ip), false);
    boolean ret = result.result == 0;
    if (result.errorMsg != null) {
        Log.d("NetworkUtils", "isAvailableByPing() called" + result.errorMsg);
    }
    if (result.successMsg != null) {
        Log.d("NetworkUtils", "isAvailableByPing() called" + result.successMsg);
    }
    return ret;
}
 
Example 18
Source Project: Android-utils   Source File: NetworkUtils.java    License: Apache License 2.0 5 votes vote down vote up
@RequiresPermission(MODIFY_PHONE_STATE)
public static void setMobileDataEnabled(final boolean enabled) {
    try {
        TelephonyManager tm = (TelephonyManager) UtilsApp.getApp().getSystemService(Context.TELEPHONY_SERVICE);
        if (tm == null) return;
        Method setMobileDataEnabledMethod = tm.getClass().getDeclaredMethod("setDataEnabled", boolean.class);
        if (null != setMobileDataEnabledMethod) {
            setMobileDataEnabledMethod.invoke(tm, enabled);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 19
Source Project: UnityBluetoothPlugin   Source File: BluetoothPlugin.java    License: Apache License 2.0 5 votes vote down vote up
@RequiresPermission(
        allOf = {"android.permission.BLUETOOTH", "android.permission.BLUETOOTH_ADMIN"}
)
private void doDiscovery() {
    Log.d(TAG, "doDiscovery()");
    if(this.mBtAdapter.isDiscovering()) {
        this.mBtAdapter.cancelDiscovery();
    }

    this.mBtAdapter.startDiscovery();
}
 
Example 20
Source Project: Android-utils   Source File: NetworkUtils.java    License: Apache License 2.0 5 votes vote down vote up
@RequiresPermission(CHANGE_WIFI_STATE)
public static void setWifiEnabled(final boolean enabled) {
    @SuppressLint("WifiManagerLeak")
    WifiManager manager = (WifiManager) UtilsApp.getApp().getSystemService(WIFI_SERVICE);
    if (manager == null) return;
    if (enabled == manager.isWifiEnabled()) return;
    manager.setWifiEnabled(enabled);
}
 
Example 21
Source Project: Android-utils   Source File: NetworkUtils.java    License: Apache License 2.0 5 votes vote down vote up
@RequiresPermission(ACCESS_NETWORK_STATE)
public static boolean isWifiConnected() {
    ConnectivityManager cm = (ConnectivityManager) UtilsApp.getApp().getSystemService(Context.CONNECTIVITY_SERVICE);
    if (cm == null) return false;
    NetworkInfo ni = cm.getActiveNetworkInfo();
    return ni != null && ni.getType() == ConnectivityManager.TYPE_WIFI;
}
 
Example 22
@RequiresPermission(allOf = {Constants.permissions.WRITE_SETTINGS,
    Constants.permissions.READ_SETTINGS})
public static RegisteredApplication
registerApplication (String pkg, boolean autoCreate, Context context,
                     CancellationSignal signal) {
    List<RegisteredApplication> list = getList(context, pkg, signal);
    if (DEBUG) {
        Log.d("RegisteredApplicationDb", "register -> existing list = " + list.toString());
    }
    return list.isEmpty() ?
            (autoCreate ? create(pkg, context) : null) : list.get(0);
}
 
Example 23
Source Project: MiPushFramework   Source File: LegacyImpl.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
@RequiresPermission(Constants.permissions.BIND)
public void connect(@Nullable final AbstractConnectionStatusListener listener) {
    if (!Utils.isServiceInstalled()) {
        Log.e("PushController", "Service not installed.");
        return;
    }
    mConnection = IPCUtils.connectService(new Intent()
                    .setComponent(new ComponentName(Constants.SERVICE_APP_NAME,
                            Constants.CONTROLLER_SERVICE_NAME)),
            getContext(), Context.BIND_AUTO_CREATE,
            new ServiceConnectionListener() {
                @Override
                public void onReady(IBinder binder) {
                    mService = IPushController.Stub.asInterface(binder);
                    if (listener != null) {
                        listener.onReady();
                    }
                }

                @Override
                public void onDisconnected() {
                    Log.e("PushController", "disconnected");
                    mService = null;
                    mConnection = null;
                    if (listener != null) {
                        listener.onDisconnected();
                    }
                }
            });
}
 
Example 24
Source Project: Android-utils   Source File: DeviceUtils.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressLint("HardwareIds")
@RequiresPermission(READ_PHONE_STATE)
public static String getMEID() {
    TelephonyManager tm =
            (TelephonyManager) UtilsApp.getApp().getSystemService(Context.TELEPHONY_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        //noinspection ConstantConditions
        return tm.getMeid();
    }
    //noinspection ConstantConditions
    return tm.getDeviceId();
}
 
Example 25
Source Project: Android-utils   Source File: DeviceUtils.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressLint("HardwareIds")
@RequiresPermission(READ_PHONE_STATE)
public static String getIMSI() {
    TelephonyManager tm =
            (TelephonyManager) UtilsApp.getApp().getSystemService(Context.TELEPHONY_SERVICE);
    //noinspection ConstantConditions
    return tm.getSubscriberId();
}
 
Example 26
Source Project: PasscodeView   Source File: Utils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Check if the device have supported hardware fir the finger print scanner.
 *
 * @param context instance of the caller.
 * @return true if device have the hardware.
 */
@SuppressWarnings("MissingPermission")
@RequiresApi(api = Build.VERSION_CODES.M)
@RequiresPermission(allOf = {Manifest.permission.USE_FINGERPRINT})
public static boolean hasSupportedFingerprintHardware(Context context) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return false;
    FingerprintManager fingerprintManager = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
    return fingerprintManager != null && fingerprintManager.isHardwareDetected();
}
 
Example 27
Source Project: Android-utils   Source File: BarUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Set the notification bar's visibility.
 * <p>Must hold {@code <uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />}</p>
 *
 * @param isVisible True to set notification bar visible, false otherwise.
 */
@RequiresPermission(EXPAND_STATUS_BAR)
public static void setNotificationBarVisibility(final boolean isVisible) {
    String methodName;
    if (isVisible) {
        methodName = (Build.VERSION.SDK_INT <= 16) ? "expand" : "expandNotificationsPanel";
    } else {
        methodName = (Build.VERSION.SDK_INT <= 16) ? "collapse" : "collapsePanels";
    }
    invokePanels(methodName);
}
 
Example 28
Source Project: UnityBluetoothPlugin   Source File: BluetoothPlugin.java    License: Apache License 2.0 5 votes vote down vote up
@RequiresPermission("android.permission.BLUETOOTH")
public void stopThread() {
    Log.d(TAG, "stop");
    if(this.mBtService != null) {
        this.mBtService.stop();
        this.mBtService = null;
    }

    if(this.mBtAdapter != null) {
        this.mBtAdapter = null;
    }

    this.SetupPlugin();
}
 
Example 29
Source Project: Android-utils   Source File: CrashHelper.java    License: Apache License 2.0 5 votes vote down vote up
@RequiresPermission(WRITE_EXTERNAL_STORAGE)
public static void init(Application application, final String crashDirPath, final OnCrashListener onCrashListener) {
    initCacheDir(application, crashDirPath);
    initAppInfo(application);
    initExceptionHandler();
    CrashHelper.onCrashListener = onCrashListener;
}
 
Example 30
@RequiresPermission(Manifest.permission.CAMERA)
public void start(CameraSource cameraSource) throws IOException, SecurityException {
    if (cameraSource == null) {
        stop();
    }

    mCameraSource = cameraSource;

    if (mCameraSource != null) {
        mStartRequested = true;
        startIfReady();
    }
}
 
Example 31
Source Project: UnityBluetoothPlugin   Source File: BluetoothPlugin.java    License: Apache License 2.0 5 votes vote down vote up
@RequiresPermission(
        allOf = {"android.permission.BLUETOOTH", "android.permission.BLUETOOTH_ADMIN"}
)
String BluetoothSetName(String name) {
    if(!this.mBtAdapter.isEnabled()) {
        return "You Must Enable The BlueTooth";
    } else if(this.mBtService.getState() != 3) {
        return "Not Connected";
    } else {
        this.mBtAdapter.setName(name);
        return "SUCCESS";
    }
}
 
Example 32
Source Project: mobikul-standalone-pos   Source File: CameraSourcePreview.java    License: MIT License 5 votes vote down vote up
@RequiresPermission(Manifest.permission.CAMERA)
public void start(CameraSource cameraSource) throws IOException, SecurityException {
    if (cameraSource == null) {
        stop();
    }

    mCameraSource = cameraSource;

    if (mCameraSource != null) {
        mStartRequested = true;
        startIfReady();
    }
}
 
Example 33
Source Project: mobikul-standalone-pos   Source File: CameraSourcePreview.java    License: MIT License 5 votes vote down vote up
@RequiresPermission(Manifest.permission.CAMERA)
private void startIfReady() throws IOException, SecurityException {
    if (mStartRequested && mSurfaceAvailable) {
        mCameraSource.start(mSurfaceView.getHolder());
        mStartRequested = false;
    }
}
 
Example 34
Source Project: mobikul-standalone-pos   Source File: CameraSource.java    License: MIT License 5 votes vote down vote up
/**
 * 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.
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            mDummySurfaceTexture = new SurfaceTexture(DUMMY_TEXTURE_NAME);
            mCamera.setPreviewTexture(mDummySurfaceTexture);
        } else {
            mDummySurfaceView = new SurfaceView(mContext);
            mCamera.setPreviewDisplay(mDummySurfaceView.getHolder());
        }
        mCamera.startPreview();

        mProcessingThread = new Thread(mFrameProcessor);
        mFrameProcessor.setActive(true);
        mProcessingThread.start();
    }
    return this;
}
 
Example 35
Source Project: Common   Source File: PhoneUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Return the IMSI.
 * <p>Must hold {@code <uses-permission android:name="android.permission.READ_PHONE_STATE" />}</p>
 *
 * @return the IMSI
 */
@SuppressLint("HardwareIds")
@RequiresPermission(READ_PHONE_STATE)
public static String getIMSI(@NonNull Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Service.TELEPHONY_SERVICE);
    return tm.getSubscriberId();
}
 
Example 36
Source Project: Common   Source File: ScreenUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Set the duration of sleep.
 * <p>Must hold {@code <uses-permission android:name="android.permission.WRITE_SETTINGS" />}</p>
 *
 * @param duration The duration.
 */
@RequiresPermission(WRITE_SETTINGS)
public static void setSleepDuration(@NonNull final Context context, final int duration) {
    Settings.System.putInt(context.getContentResolver(),
            Settings.System.SCREEN_OFF_TIMEOUT,
            duration);
}
 
Example 37
Source Project: Common   Source File: DeviceUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Enable or disable wifi.
 * <p>Must hold {@code <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />}</p>
 *
 * @param enabled True to enabled, false otherwise.
 */
@RequiresPermission(CHANGE_WIFI_STATE)
private static void setWifiEnabled(@NonNull final Context context, final boolean enabled) {
    @SuppressLint("WifiManagerLeak")
    WifiManager manager = (WifiManager) context.getSystemService(WIFI_SERVICE);
    if (manager == null) return;
    if (enabled == manager.isWifiEnabled()) return;
    manager.setWifiEnabled(enabled);
}
 
Example 38
Source Project: Barcode-Reader   Source File: CameraSourcePreview.java    License: Apache License 2.0 5 votes vote down vote up
@RequiresPermission(Manifest.permission.CAMERA)
public void start(CameraSource cameraSource) throws IOException, SecurityException {
    if (cameraSource == null) {
        stop();
    }

    mCameraSource = cameraSource;

    if (mCameraSource != null) {
        mStartRequested = true;
        startIfReady();
    }
}
 
Example 39
@SuppressLint("MissingPermission")
@RequiresPermission(allOf = {Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION})
public void requestSingleUpdate(@Nullable String provider) {
    if (mLocationManager == null || mLocationListener == null || provider == null) {
        LogUtil.w(TAG, "Cannot request single update with specified provider");

        return;
    }

    if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_LOCATION)) {
        LogUtil.w(TAG, "Cannot request single update with specified provider, location feature is not available");

        return;
    }

    if (isProviderCompatible(provider)) {
        LogUtil.d(TAG, "Trying to request single update with specified provider...");
        try {
            mLocationManager.requestSingleUpdate(provider, mLocationListener, null);
        } catch (Exception e) {
            LogUtil.e(TAG, "Exception while trying to request single update with specified provider");

            LogUtil.e(TAG, e.getMessage());
            LogUtil.e(TAG, e.toString());

            e.printStackTrace();
        }
    } else {
        LogUtil.w(TAG, "Cannot request single update with specified provider, selected provider is not compatible");
    }
}
 
Example 40
@SuppressLint("MissingPermission")
@RequiresPermission(allOf = {Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION})
public void requestLocationUpdates(@Nullable String provider, long minTime, float minDistance) {
    if (mLocationManager == null || mLocationListener == null || provider == null) {
        LogUtil.w(TAG, "Cannot request location updates with specified provider, time and distance");

        return;
    }

    if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_LOCATION)) {
        LogUtil.w(TAG, "Cannot request location updates with specified provider, time and distance, location feature is not available");

        return;
    }

    if (isProviderCompatible(provider)) {
        LogUtil.d(TAG, "Trying to request location updates with specified provider, time and distance...");
        try {
            mLocationManager.requestLocationUpdates(provider, minTime, minDistance, mLocationListener);
        } catch (Exception e) {
            LogUtil.e(TAG, "Exception while trying to request location updates with specified provider, time and distance");

            LogUtil.e(TAG, e.getMessage());
            LogUtil.e(TAG, e.toString());

            e.printStackTrace();
        }
    } else {
        LogUtil.w(TAG, "Cannot request location updates with specified provider, time and distance, selected provider is not compatible");
    }
}