android.support.annotation.RequiresPermission Java Examples

The following examples show how to use android.support.annotation.RequiresPermission. 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 check out the related API usage on the sidebar.
Example #1
Source Project: VehicleInfoOCR   Author: Udayraj123   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
Source Project: Barcode-Reader   Author: ravi8x   File: CameraSourcePreview.java    License: BSD 3-Clause "New" or "Revised" 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 #3
Source Project: Android-utils   Author: Shouheng88   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   Author: Shouheng88   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   Author: Shouheng88   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   Author: snailflying   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   Author: webkul   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   Author: avaneeshkumarmaurya   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   Author: avaneeshkumarmaurya   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
Source Project: Barcode-Reader   Author: ravi8x   File: CameraSource.java    License: BSD 3-Clause "New" or "Revised" 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 #11
Source Project: NFC-EMV-Reader   Author: n37sn4k3   File: LocationService.java    License: GNU General Public License v3.0 6 votes vote down vote up
@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
Source Project: Machine-Learning-Projects-for-Mobile-Applications   Author: PacktPublishing   File: Camera2Source.java    License: MIT License 6 votes vote down vote up
/**
 * 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   Author: hss01248   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   Author: rlatkdgus500   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   Author: DevipriyaSarkar   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   Author: MiPushFramework   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   Author: Shouheng88   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   Author: Shouheng88   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   Author: rlatkdgus500   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   Author: Shouheng88   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   Author: Shouheng88   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
Source Project: MiPushFramework   Author: MiPushFramework   File: RegisteredApplicationDb.java    License: GNU General Public License v3.0 5 votes vote down vote up
@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   Author: MiPushFramework   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   Author: Shouheng88   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   Author: Shouheng88   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   Author: kevalpatel2106   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   Author: Shouheng88   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   Author: rlatkdgus500   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   Author: Shouheng88   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
Source Project: ETHWallet   Author: snailflying   File: CameraSourcePreview.java    License: GNU General Public License v3.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();
    }
}