Search in sources :

Example 26 with RequiresPermission

use of androidx.annotation.RequiresPermission in project react-native-app-upgrade by songxiaoliang.

the class ApkInstallUtils method installAppSilentAbove24.

// ===============================//
/**
 * 静默安装 App 在Android7.0及以上起作用
 * <p>非 root 需添加权限
 * {@code <uses-permission android:name="android.permission.INSTALL_PACKAGES" />}</p>
 *
 * @param filePath 文件路径
 * @return {@code true}: 安装成功<br>{@code false}: 安装失败
 */
@RequiresPermission(INSTALL_PACKAGES)
private static boolean installAppSilentAbove24(Context context, String packageName, String filePath) {
    File file = FileUtils.getFileByPath(filePath);
    if (!FileUtils.isFileExists(context, file)) {
        return false;
    }
    boolean isRoot = isDeviceRooted();
    String command = "pm install -i " + packageName + " --user 0 " + filePath;
    ShellUtils.CommandResult commandResult = ShellUtils.execCommand(command, isRoot);
    return (commandResult.successMsg != null && commandResult.successMsg.toLowerCase().contains("success"));
}
Also used : File(java.io.File) RequiresPermission(androidx.annotation.RequiresPermission)

Example 27 with RequiresPermission

use of androidx.annotation.RequiresPermission in project Signal-Android by signalapp.

the class Util method getDeviceNumber.

@RequiresPermission(anyOf = { android.Manifest.permission.READ_PHONE_STATE, android.Manifest.permission.READ_SMS, android.Manifest.permission.READ_PHONE_NUMBERS })
@SuppressLint("MissingPermission")
public static Optional<Phonenumber.PhoneNumber> getDeviceNumber(Context context) {
    try {
        final String localNumber = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getLine1Number();
        final Optional<String> countryIso = getSimCountryIso(context);
        if (TextUtils.isEmpty(localNumber))
            return Optional.absent();
        if (!countryIso.isPresent())
            return Optional.absent();
        return Optional.fromNullable(PhoneNumberUtil.getInstance().parse(localNumber, countryIso.get()));
    } catch (NumberParseException e) {
        Log.w(TAG, e);
        return Optional.absent();
    }
}
Also used : TelephonyManager(android.telephony.TelephonyManager) NumberParseException(com.google.i18n.phonenumbers.NumberParseException) SpannableString(android.text.SpannableString) RequiresPermission(androidx.annotation.RequiresPermission) SuppressLint(android.annotation.SuppressLint)

Example 28 with RequiresPermission

use of androidx.annotation.RequiresPermission in project Signal-Android by signalapp.

the class WallpaperImageSelectionActivity method getIntent.

@RequiresPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
public static Intent getIntent(@NonNull Context context, @Nullable RecipientId recipientId) {
    Intent intent = new Intent(context, WallpaperImageSelectionActivity.class);
    intent.putExtra(EXTRA_RECIPIENT_ID, recipientId);
    return intent;
}
Also used : Intent(android.content.Intent) RequiresPermission(androidx.annotation.RequiresPermission)

Example 29 with RequiresPermission

use of androidx.annotation.RequiresPermission in project prebid-mobile-android by prebid.

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();
        // 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;
}
Also used : SurfaceTexture(android.graphics.SurfaceTexture) SurfaceView(android.view.SurfaceView) RequiresPermission(androidx.annotation.RequiresPermission)

Example 30 with RequiresPermission

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

the class WebSocketRecognitionService method configure.

@RequiresPermission(RECORD_AUDIO)
@Override
protected void configure(Intent recognizerIntent) throws IOException {
    Bundle bundle = getExtras();
    ChunkedWebRecSessionBuilder builder = new ChunkedWebRecSessionBuilder(this, bundle, null);
    List<Pair<String, String>> list = QueryUtils.getQueryParams(recognizerIntent, builder);
    list.add(new Pair<>("content-type", getAudioRecorder().getContentType()));
    mUrl = QueryUtils.combine(getServerUrl(R.string.keyWsServer, R.string.defaultWsServer), QueryUtils.encodeKeyValuePairs(list, "UTF-8"));
    // Extra overrides the preferences
    boolean isUnlimitedDuration;
    Object obj = bundle.get(Extras.EXTRA_UNLIMITED_DURATION);
    if (obj == null) {
        obj = bundle.get(Extras.EXTRA_DICTATION_MODE);
    }
    if (obj == null) {
        isUnlimitedDuration = !PreferenceUtils.getPrefBoolean(getSharedPreferences(), getResources(), R.string.keyWsAutoStopAfterPause, R.bool.defaultWsAutoStopAfterPause);
    } else {
        isUnlimitedDuration = (Boolean) obj;
    }
    configureHandler(isUnlimitedDuration, bundle.getBoolean(RecognizerIntent.EXTRA_PARTIAL_RESULTS, false));
}
Also used : Bundle(android.os.Bundle) ChunkedWebRecSessionBuilder(ee.ioc.phon.android.speak.ChunkedWebRecSessionBuilder) Pair(android.util.Pair) 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