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 File: Downloader.java    From Android-VMLib with 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 #2
Source File: DeviceUtils.java    From Android-utils with 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 #3
Source File: CameraSourcePreview.java    From Barcode-Reader with 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 #4
Source File: CameraSource.java    From Barcode-Reader with 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 #5
Source File: DeviceUtils.java    From Android-utils with 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 #6
Source File: CameraSource.java    From Barcode-Reader with 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 #7
Source File: CameraSource.java    From mobikul-standalone-pos with 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 File: LocationService.java    From NFC-EMV-Reader with 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 #9
Source File: Camera2Source.java    From Machine-Learning-Projects-for-Mobile-Applications with 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 #10
Source File: CameraSource.java    From VehicleInfoOCR with 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 #11
Source File: CameraSource.java    From ETHWallet with 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 #12
Source File: CameraSourcePreview.java    From OCR-Reader with 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 #13
Source File: CameraSourcePreview.java    From Barcode-Reader with 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 #14
Source File: BluetoothPlugin.java    From UnityBluetoothPlugin with 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 File: BigImageView.java    From ImageLoader with 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 #16
Source File: CameraSourcePreview.java    From ETHWallet with 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();
    }
}
 
Example #17
Source File: CameraSource.java    From mobikul-standalone-pos with 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 #18
Source File: PhoneUtils.java    From Common with 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 #19
Source File: ScreenUtils.java    From Common with 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 #20
Source File: BluetoothPlugin.java    From UnityBluetoothPlugin with 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 #21
Source File: CameraSourcePreview.java    From mobikul-standalone-pos with 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 #22
Source File: LocationService.java    From NFC-EMV-Reader with GNU General Public License v3.0 5 votes vote down vote up
@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");
    }
}
 
Example #23
Source File: PluginInterceptActivity.java    From Phantom with Apache License 2.0 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
@Override
public void startActivityFromChild(@NonNull Activity child, @RequiresPermission Intent intent,
                                   int requestCode, @Nullable Bundle options) {
    mContentProxy.getContext().startActivityFromChild(child,
            mContentProxy.setActivityIntentExtra(intent), requestCode, options);
}
 
Example #24
Source File: EventDb.java    From MiPushFramework with GNU General Public License v3.0 5 votes vote down vote up
@RequiresPermission(value = Constants.permissions.READ_SETTINGS)
public static List<Event> query(String pkg, int page, Context context,
                                CancellationSignal cancellationSignal) {
    int skip;
    int limit;
    skip = Constants.PAGE_SIZE * (page - 1);
    limit = Constants.PAGE_SIZE;
    return query(skip, limit, pkg, context, cancellationSignal);
}
 
Example #25
Source File: BluetoothService.java    From UnityBluetoothPlugin with Apache License 2.0 5 votes vote down vote up
@RequiresPermission("android.permission.BLUETOOTH")
public synchronized void start() {
    Log.d(TAG, "start");

    // Cancel any thread attempting to make a connection
    if (mConnectThread != null) {
        mConnectThread.cancel();
        mConnectThread = null;
    }

    // Cancel any thread currently running a connection
    if (mConnectedThread != null) {
        mConnectedThread.cancel();
        mConnectedThread = null;
    }

    // If Accept Tread is null, create and start
    if (mAcceptThread != null) {

    }
    else {
        this.mAcceptThread = new BluetoothService.AcceptThread();
        this.mAcceptThread.start();
    }

    this.setState(STATE_LISTEN);
}
 
Example #26
Source File: CameraUtil.java    From AndroidDemo with MIT License 5 votes vote down vote up
@SuppressLint("MissingPermission")
@RequiresPermission(android.Manifest.permission.CAMERA)
private void openCamera(CameraManager cameraManager, CameraConfig config) {
    try {
        cameraManager.openCamera(config.cameraId, config.cameraStateCallback, handler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example #27
Source File: CameraSource.java    From trust-wallet-android-source with GNU General Public License v3.0 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 #28
Source File: EventDb.java    From MiPushFramework with GNU General Public License v3.0 5 votes vote down vote up
@RequiresPermission(value = Constants.permissions.WRITE_SETTINGS)
public static Uri insertEvent(@Event.ResultType int result,
                              EventType type,
                              Context context) {
    return insertEvent(type.fillEvent(new Event(null, type.getPkg(), type.getType(), Utils.getUTC().getTime()
            , result, null, null, type.getInfo())), context);
}
 
Example #29
Source File: CameraSourcePreview.java    From mobikul-standalone-pos with 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 #30
Source File: CameraSourcePreview.java    From Barcode-Reader with 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();
    }
}