public SQLitePlugin(ReactApplicationContext reactContext) { super(reactContext); this.context = reactContext.getApplicationContext(); this.threadPool = Executors.newCachedThreadPool(); }
protected void openIntentChooser() throws ActivityNotFoundException { if(this.options.hasKey("forceDialog") && this.options.getBoolean("forceDialog")){ Intent chooser = Intent.createChooser(this.getIntent(), this.chooserTitle); chooser.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); this.reactContext.startActivity(chooser); }else{ this.getIntent().setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); this.reactContext.startActivity(this.getIntent()); } } }
private boolean isSensorAvailable() { if (ActivityCompat.checkSelfPermission(mReactContext, Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) { return false; } return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && (mReactContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT) || ((FingerprintManager) mReactContext.getSystemService(Context.FINGERPRINT_SERVICE)).isHardwareDetected()); }
protected Intent[] getIntentsToViewFile(Intent intent, Uri uri) { PackageManager pm = this.reactContext.getPackageManager(); List<ResolveInfo> resInfo = pm.queryIntentActivities(intent, 0); Intent[] extraIntents = new Intent[resInfo.size()]; for (int i = 0; i < resInfo.size(); i++) { ResolveInfo ri = resInfo.get(i); String packageName = ri.activityInfo.packageName; Intent newIntent = new Intent(); newIntent.setComponent(new ComponentName(packageName, ri.activityInfo.name)); newIntent.setAction(Intent.ACTION_VIEW); newIntent.setDataAndType(uri, intent.getType()); newIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); extraIntents[i] = new Intent(newIntent); } return extraIntents; } protected void openIntentChooser() throws ActivityNotFoundException {
public DocumentPicker(ReactApplicationContext reactContext) { super(reactContext); reactContext.addActivityEventListener(this); }
private void sendEvent(String eventName, @Nullable WritableMap params) { this.context .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) .emit(eventName, params); }
private String getUserSerial() { //noinspection ResourceType Object userManager = getReactApplicationContext().getSystemService("user"); if (null == userManager) return ""; try { Method myUserHandleMethod = android.os.Process.class.getMethod("myUserHandle", (Class<?>[]) null); Object myUserHandle = myUserHandleMethod.invoke(android.os.Process.class, (Object[]) null); Method getSerialNumberForUser = userManager.getClass().getMethod("getSerialNumberForUser", myUserHandle.getClass()); Long userSerial = (Long) getSerialNumberForUser.invoke(userManager, myUserHandle); if (userSerial != null) { return String.valueOf(userSerial); } else { return ""; } } catch (NoSuchMethodException | IllegalArgumentException | InvocationTargetException | IllegalAccessException ignored) { } return ""; }
public void run() { if (mDialog != null) mDialog.dismiss(); mDialog = mBuilder.build(); if(numberOfItems > 0) { WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(mDialog.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.WRAP_CONTENT; int dp = (int) (getReactApplicationContext().getResources().getDimension(R.dimen.md_listitem_height) / getReactApplicationContext().getResources().getDisplayMetrics().density); float pixels = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp * (numberOfItems +3), getReactApplicationContext().getResources().getDisplayMetrics()); lp.height = (int) pixels; mDialog.getWindow().setAttributes(lp); } mDialog.show(); } });
private WritableMap metaDataFromContentResolver(Uri uri) { WritableMap map = Arguments.createMap(); ContentResolver contentResolver = getReactApplicationContext().getContentResolver(); map.putString(Fields.TYPE, contentResolver.getType(uri)); Cursor cursor = contentResolver.query(uri, null, null, null, null, null); try { if (cursor != null && cursor.moveToFirst()) { map.putString(Fields.FILE_NAME, cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME))); int sizeIndex = cursor.getColumnIndex(OpenableColumns.SIZE); if (!cursor.isNull(sizeIndex)) { String size = cursor.getString(sizeIndex); if (size != null) map.putInt(Fields.FILE_SIZE, Integer.valueOf(size)); } } } finally { if (cursor != null) { cursor.close(); } } return map; }
private WritableMap metaDataFromUri(Uri uri) { WritableMap map = Arguments.createMap(); File outputDir = getReactApplicationContext().getCacheDir(); try { File downloaded = download(uri, outputDir); map.putInt(Fields.FILE_SIZE, (int) downloaded.length()); map.putString(Fields.FILE_NAME, downloaded.getName()); map.putString(Fields.TYPE, mimeTypeFromName(uri.toString())); } catch (IOException e) { Log.e("DocumentPicker", "Failed to download file", e); } return map; }
@ReactMethod public void show(ReadableMap args, Callback callback) { Intent intent; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) { intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); } else { intent = new Intent(Intent.ACTION_PICK); } intent.addCategory(Intent.CATEGORY_OPENABLE); if (!args.isNull("filetype")) { ReadableArray filetypes = args.getArray("filetype"); if (filetypes.size() > 0) { intent.setType(filetypes.getString(0)); } } this.callback = callback; getReactApplicationContext().startActivityForResult(intent, READ_REQUEST_CODE, Bundle.EMPTY); }
protected void openIntentChooser() throws ActivityNotFoundException { Intent chooser = Intent.createChooser(this.getIntent(), this.chooserTitle); chooser.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (ShareIntent.hasValidKey("showAppsToView", options) && ShareIntent.hasValidKey("url", options)) { Intent viewIntent = new Intent(Intent.ACTION_VIEW); viewIntent.setType(this.fileShare.getType()); Intent[] viewIntents = this.getIntentsToViewFile(viewIntent, this.fileShare.getURI()); chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, viewIntents); } this.reactContext.startActivity(chooser); } public static boolean isPackageInstalled(String packagename, Context context) {
@ReactMethod public void isSensorAvailable(final Promise promise) { response = Arguments.createMap(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (ActivityCompat.checkSelfPermission(mReactContext, Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) { sendResponse("failed", "You haven't allow this app to use your fingerprint sensor", promise); return; } if (mReactContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT) || ((FingerprintManager) mReactContext.getSystemService(Context.FINGERPRINT_SERVICE)).isHardwareDetected()) { if (((FingerprintManager) mReactContext.getSystemService(Context.FINGERPRINT_SERVICE)).hasEnrolledFingerprints()) { sendResponse("ok", null, promise); } else { sendResponse("failed", "You have fingerprint sensor, but you should set it enabled in your settings to use with this app", promise); } } else { sendResponse("failed", "You don\'t have appropriate hardware", promise); } } else { sendResponse("failed", "You don\'t have appropriate hardware", promise); } }
private boolean isCallable(Intent intent) { List<ResolveInfo> list = getReactApplicationContext().getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); return list.size() > 0; }
public SQLitePlugin(ReactApplicationContext reactContext) { super(reactContext); this.context = reactContext.getApplicationContext(); this.threadPool = Executors.newCachedThreadPool(); }
@ReactMethod public void play(String path) { Intent intent = new Intent(this.context, PlayerActivity.class); intent.putExtra(PlayerActivity.LOCATION, path); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); this.context.startActivity(intent); }
final String authority = ((ShareApplication) reactContext.getApplicationContext()).getFileProviderAuthority();
public ArrayList<Uri> getURI() { final MimeTypeMap mime = MimeTypeMap.getSingleton(); ArrayList<Uri> finalUris = new ArrayList<>(); final String authority = ((ShareApplication) reactContext.getApplicationContext()).getFileProviderAuthority();
public ActivityRecognizer(ReactApplicationContext reactContext) { mGoogleApiAvailability = GoogleApiAvailability.getInstance(); mContext = reactContext.getApplicationContext(); mReactContext = reactContext; connected = false; started = false; if (checkPlayServices()) { mBroadcastReceiver = new ActivityDetectionBroadcastReceiver(); mGoogleApiClient = new GoogleApiClient.Builder(mContext) .addApi(ActivityRecognition.API) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build(); } }