private int getResourceForMedia(Resources resources, Uri uri) {
   int drawable = 0;
   if (uri.getScheme().equals("file")) {
     if (uri.getLastPathSegment().endsWith("3gp")) {
       drawable = R.drawable.media_film;
     } else if (uri.getLastPathSegment().endsWith("jpg")) {
       drawable = R.drawable.media_camera;
     } else if (uri.getLastPathSegment().endsWith("txt")) {
       drawable = R.drawable.media_notepad;
     }
   } else if (uri.getScheme().equals("content")) {
     if (uri.getAuthority().equals(GPStracking.AUTHORITY + ".string")) {
       drawable = R.drawable.media_mark;
     } else if (uri.getAuthority().equals("media")) {
       drawable = R.drawable.media_speech;
     }
   }
   synchronized (sBitmapCache) {
     if (sBitmapCache.get(drawable) == null) {
       Bitmap bitmap = BitmapFactory.decodeResource(resources, drawable);
       sBitmapCache.put(drawable, bitmap);
     }
   }
   return drawable;
 }
Example #2
0
  public static boolean matchesContentUri(Uri uri, Uri baseContentUri) {
    if (uri == null) {
      return false;
    }

    // Check that scheme and authority are the same.
    if (!uri.getScheme().equals(baseContentUri.getScheme())
        || !uri.getAuthority().equals(baseContentUri.getAuthority())) {
      return false;
    }

    // Checks that all the base path components are in the URI.
    List<String> uriPathSegments = uri.getPathSegments();
    List<String> basePathSegments = baseContentUri.getPathSegments();
    if (basePathSegments.size() > uriPathSegments.size()) {
      return false;
    }
    for (int i = 0; i < basePathSegments.size(); i++) {
      if (!uriPathSegments.get(i).equals(basePathSegments.get(i))) {
        return false;
      }
    }

    return true;
  }
 private Attachment(UUID uuid, Bitmap bitmap, Uri uri) {
   String attachmentUrl;
   boolean z = true;
   this.callId = uuid;
   this.bitmap = bitmap;
   this.originalUri = uri;
   if (uri != null) {
     String scheme = uri.getScheme();
     if ("content".equalsIgnoreCase(scheme)) {
       this.isContentUri = true;
       if (uri.getAuthority() == null || uri.getAuthority().startsWith("media")) {
         z = false;
       }
       this.shouldCreateFile = z;
     } else if ("file".equalsIgnoreCase(uri.getScheme())) {
       this.shouldCreateFile = true;
     } else if (!Utility.isWebUri(uri)) {
       throw new FacebookException("Unsupported scheme for media Uri : " + scheme);
     }
   } else if (bitmap != null) {
     this.shouldCreateFile = true;
   } else {
     throw new FacebookException("Cannot share media without a bitmap or Uri set");
   }
   this.attachmentName = !this.shouldCreateFile ? null : UUID.randomUUID().toString();
   if (this.shouldCreateFile) {
     attachmentUrl =
         FacebookContentProvider.getAttachmentUrl(
             FacebookSdk.getApplicationId(), uuid, this.attachmentName);
   } else {
     attachmentUrl = this.originalUri.toString();
   }
   this.attachmentUrl = attachmentUrl;
 }
 private Integer getResourceForMedia(Resources resources, Uri uri) {
   int drawable = 0;
   if (uri.getScheme().equals("file")) {
     if (uri.getLastPathSegment().endsWith("3gp")) {
       drawable = R.drawable.media_film;
     } else if (uri.getLastPathSegment().endsWith("jpg")) {
       drawable = R.drawable.media_camera;
     } else if (uri.getLastPathSegment().endsWith("txt")) {
       drawable = R.drawable.media_notepad;
     }
   } else if (uri.getScheme().equals("content")) {
     if (uri.getAuthority().equals(GPStracking.AUTHORITY + ".string")) {
       drawable = R.drawable.media_mark;
     } else if (uri.getAuthority().equals("media")) {
       drawable = R.drawable.media_speech;
     }
   }
   Bitmap bitmap = null;
   Integer bitmapKey = new Integer(drawable);
   synchronized (sBitmapCache) {
     if (!sBitmapCache.containsKey(bitmapKey)) {
       bitmap = BitmapFactory.decodeResource(resources, drawable);
       sBitmapCache.put(bitmapKey, bitmap);
     }
     bitmap = sBitmapCache.get(bitmapKey);
   }
   return bitmapKey;
 }
Example #5
0
 private boolean isChildImageUri(Uri uri) {
   // Sometimes, the URI of an image contains a query string with key
   // "bucketId" inorder to restore the image list. However, the query
   // string is not part of the mBaseUri. So, we check only other parts
   // of the two Uri to see if they are the same.
   Uri base = mBaseUri;
   return Util.equals(base.getScheme(), uri.getScheme())
       && Util.equals(base.getHost(), uri.getHost())
       && Util.equals(base.getAuthority(), uri.getAuthority())
       && Util.equals(base.getPath(), getPathWithoutId(uri));
 }
Example #6
0
 public static Uri normalizeUri(Uri uri) {
   if (uri == null) {
     return uri;
   }
   Uri normalized = uri.normalizeScheme();
   if (normalized.getAuthority() != null) {
     normalized =
         normalized
             .buildUpon()
             .encodedAuthority(normalized.getAuthority().toLowerCase(Locale.getDefault()))
             .build();
   }
   return Uri.parse(trimLinkPreviewUrls(normalized));
 }
Example #7
0
 public static a a(String s, Uri uri) {
   s = (new android.net.Uri.Builder()).scheme("android-app").authority(s);
   if (uri != null) {
     s.appendPath(uri.getScheme());
     if (uri.getAuthority() != null) {
       s.appendPath(uri.getAuthority());
     }
     for (Iterator iterator = uri.getPathSegments().iterator();
         iterator.hasNext();
         s.appendPath((String) iterator.next())) {}
     s.encodedQuery(uri.getEncodedQuery()).encodedFragment(uri.getEncodedFragment());
   }
   return new a(s.build());
 }
 public Drawable getTheDrawable(Uri uri) throws FileNotFoundException {
   String authority = uri.getAuthority();
   Resources r;
   if (TextUtils.isEmpty(authority)) {
     throw new FileNotFoundException("No authority: " + uri);
   } else {
     try {
       r = mContext.getPackageManager().getResourcesForApplication(authority);
     } catch (NameNotFoundException ex) {
       throw new FileNotFoundException("No package found for authority: " + uri);
     }
   }
   List<String> path = uri.getPathSegments();
   if (path == null) {
     throw new FileNotFoundException("No path: " + uri);
   }
   int len = path.size();
   int id;
   if (len == 1) {
     try {
       id = Integer.parseInt(path.get(0));
     } catch (NumberFormatException e) {
       throw new FileNotFoundException("Single path segment is not a resource ID: " + uri);
     }
   } else if (len == 2) {
     id = r.getIdentifier(path.get(1), path.get(0), authority);
   } else {
     throw new FileNotFoundException("More than two path segments: " + uri);
   }
   if (id == 0) {
     throw new FileNotFoundException("No resource found for: " + uri);
   }
   return r.getDrawable(id);
 }
Example #9
0
  @DSComment("Private Method")
  @DSBan(DSCat.PRIVATE_METHOD)
  @DSGenerator(
      tool_name = "Doppelganger",
      tool_version = "2.0",
      generated_on = "2013-12-30 12:28:26.964 -0500",
      hash_original_method = "7C7E876780A603240D42A5BB96522037",
      hash_generated_method = "EAAD1702E472810FAA2CF3F810517246")
  private static String getTitle(Context context, Uri uri, boolean followSettingsUri) {
    Cursor cursor = null;
    ContentResolver res = context.getContentResolver();

    String title = null;

    if (uri != null) {
      String authority = uri.getAuthority();

      if (Settings.AUTHORITY.equals(authority)) {
        if (followSettingsUri) {
          Uri actualUri =
              RingtoneManager.getActualDefaultRingtoneUri(
                  context, RingtoneManager.getDefaultType(uri));
          String actualTitle = getTitle(context, actualUri, false);
          title =
              context.getString(
                  com.android.internal.R.string.ringtone_default_with_actual, actualTitle);
        }
      } else {

        if (DrmStore.AUTHORITY.equals(authority)) {
          cursor = res.query(uri, DRM_COLUMNS, null, null, null);
        } else if (MediaStore.AUTHORITY.equals(authority)) {
          cursor = res.query(uri, MEDIA_COLUMNS, null, null, null);
        }

        try {
          if (cursor != null && cursor.getCount() == 1) {
            cursor.moveToFirst();
            return cursor.getString(2);
          } else {
            title = uri.getLastPathSegment();
          }
        } finally {
          if (cursor != null) {
            cursor.close();
          }
        }
      }
    }

    if (title == null) {
      title = context.getString(com.android.internal.R.string.ringtone_unknown);

      if (title == null) {
        title = "";
      }
    }

    return title;
  }
 private void createArtChangedBroadcastReceiver(Context paramContext) {
   IntentFilter localIntentFilter = new IntentFilter();
   localIntentFilter.addAction("com.google.android.music.AlbumArtChanged");
   localIntentFilter.addCategory("android.intent.category.DEFAULT");
   Uri localUri = MusicContent.Albums.getAlbumsUri(0L);
   String str1 = localUri.getAuthority();
   localIntentFilter.addDataAuthority(str1, null);
   String str2 = localUri.getScheme();
   localIntentFilter.addDataScheme(str2);
   try {
     localIntentFilter.addDataType("vnd.android.cursor.item/vnd.google.music.album");
     AlbumArtChangedBroadcastReceiver localAlbumArtChangedBroadcastReceiver1 =
         new AlbumArtChangedBroadcastReceiver(null);
     this.mAlbumArtChangedBroadcastReceiver = localAlbumArtChangedBroadcastReceiver1;
     AlbumArtChangedBroadcastReceiver localAlbumArtChangedBroadcastReceiver2 =
         this.mAlbumArtChangedBroadcastReceiver;
     Intent localIntent =
         paramContext.registerReceiver(localAlbumArtChangedBroadcastReceiver2, localIntentFilter);
     return;
   } catch (IntentFilter.MalformedMimeTypeException localMalformedMimeTypeException) {
     while (true) {
       StringBuilder localStringBuilder =
           new StringBuilder().append("Error setting data type on filter: ");
       String str3 = localMalformedMimeTypeException.getMessage();
       String str4 = str3;
       int i = Log.e("AlbumArtDownload", str4);
     }
   }
 }
 public boolean b(Uri uri) {
   String scheme = uri.getScheme();
   if (scheme == null || !scheme.equals("gmsg")) {
     return false;
   }
   scheme = uri.getAuthority();
   return scheme != null && scheme.equals("mobileads.google.com");
 }
  private void handleActivityResult(@NonNull Intent data, int reqCode) throws SecurityException {
    final Uri uri;
    String filePath = null;
    if (reqCode == REQUEST_PICK_FILE) {
      uri = data.getData();
      if (uri != null) {
        filePath = uri.getPath();
      }
    } else {
      uri = null;
      filePath = data.getStringExtra("path");
    }

    Timber.i("uri: %s, filepath: %s", uri, filePath);

    if (!Utils.fileExists(filePath) && uri != null) {
      final ContentResolver cr = getContentResolver();
      Cursor cursor = null;
      try {
        cursor = cr.query(uri, null, null, null, null);
        if (cursor != null && cursor.moveToNext()) {
          int index = cursor.getColumnIndex(MediaStore.MediaColumns.DATA);
          if (index >= 0) {
            filePath = cursor.getString(index);
          } else if (Build.VERSION.SDK_INT >= 19
              && uri.toString().startsWith(ContentResolver.SCHEME_CONTENT)) {
            String newUri =
                new Uri.Builder()
                    .scheme(ContentResolver.SCHEME_CONTENT)
                    .authority(uri.getAuthority())
                    .appendPath("document")
                    .build()
                    .toString();
            String path = uri.toString();
            index = filePath.indexOf(":");
            if (path.startsWith(newUri) && index >= 0) {
              String firstPath = filePath.substring(0, index);
              filePath = filePath.substring(index + 1);
              String storage = IOUtils.get().getPrimarySdCard();
              if (!firstPath.contains(ROOT_ID_PRIMARY_EMULATED)) {
                storage = IOUtils.get().getSecondarySdCard();
              }
              filePath = storage + "/" + filePath;
            } else {
              filePath = null;
            }
          }
        }
      } finally {
        if (cursor != null) cursor.close();
      }
    }

    if (sCallback != null) {
      sCallback.fileRequested(filePath);
    }
  }
  /**
   * Implementation is provided by the parent class. Can be overridden to provide additional
   * functionality, but subclasses <em>must</em> always call the superclass. If the superclass
   * returns {@code null}, the subclass may implement custom behavior.
   *
   * <p>This is typically used to resolve a subtree URI into a concrete document reference, issuing
   * a narrower single-document URI permission grant along the way.
   *
   * @see io.noobdev.neuteredsaf.compat.DocumentsContractCompat#buildDocumentUriUsingTree(Uri,
   *     String)
   */
  @Override
  public Uri canonicalize(@NonNull Uri uri) {
    switch (mMatcher.match(uri)) {
      case MATCH_DOCUMENT_TREE:
        enforceTree(uri);

        return buildDocumentUri(uri.getAuthority(), getDocumentId(uri));
    }
    return null;
  }
Example #14
0
 public String getPath(Uri uri) {
   if (null == uri || uri.getAuthority().equals("")) {
     return null;
   }
   String[] projection = {MediaStore.Images.Media.DATA};
   Cursor cursor = HomePageActivity.this.managedQuery(uri, projection, null, null, null);
   int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
   cursor.moveToFirst();
   String path = cursor.getString(column_index);
   return path;
 }
  public static boolean isAppStoreURI(Uri uri) {

    return uri.getAuthority().contains("play.google.com")
        || // play store
        uri.getScheme().equals("market")
        || // play store scheme
        uri.getScheme().equals("amzn")
        || // amazon store
        uri.toString().contains("www.amazon.com/gp/mas/dl/android")
        || // amazon store http
        uri.getScheme().equals("samsungapps"); // samsung app store
  }
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK && requestCode == 0) {
      requestAllState();

    } else if (requestCode == FLAG_CHOOSE_IMG && resultCode == RESULT_OK) { // 选择图片
      if (data != null) {
        Uri uri = data.getData();
        if (!TextUtils.isEmpty(uri.getAuthority())) {
          Cursor cursor =
              getContentResolver()
                  .query(uri, new String[] {MediaStore.Images.Media.DATA}, null, null, null);
          if (null == cursor) {
            Toast.makeText(this, "图片没找到", Toast.LENGTH_SHORT).show();
            return;
          }
          cursor.moveToFirst();
          String path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA));
          cursor.close();
          Log.i("===", "path=" + path);
          Intent intent = new Intent(this, CropImageActivity.class);
          intent.putExtra("path", path);
          startActivityForResult(intent, FLAG_MODIFY_FINISH);

        } else {
          Log.i("===", "path=" + uri.getPath());
          Intent intent = new Intent(this, CropImageActivity.class);
          intent.putExtra("path", uri.getPath());
          startActivityForResult(intent, FLAG_MODIFY_FINISH);
        }
      }
    } else if (requestCode == FLAG_CHOOSE_PHONE && resultCode == RESULT_OK) { // 拍照
      File f = new File(FILE_PIC_SCREENSHOT, localTempImageFileName);
      Intent intent = new Intent(this, CropImageActivity.class);
      intent.putExtra("path", f.getAbsolutePath());
      startActivityForResult(intent, FLAG_MODIFY_FINISH);

    } else if (requestCode == FLAG_MODIFY_FINISH && resultCode == RESULT_OK) {
      if (data != null) {
        final String path = data.getStringExtra("path");
        Log.i("===", "截取到的图片路径是 = " + path);

        Bitmap b = BitmapFactory.decodeFile(path);

        headImageView.setImageBitmap(b);

        headerImageStr = bitmap2Base64(b);

        requestSetUserLogo();
      }
    }
  }
 @Override
 public String getType(Uri uri) {
   // Match any authority. The app decides and restricts the authorities this provider responds to
   // see http://stackoverflow.com/a/10791144/844882.
   UriMatcher matcher = new UriMatcher(UriMatcher.NO_MATCH);
   matcher.addURI(uri.getAuthority(), "item/#", ITEM_ID);
   int match = matcher.match(uri);
   switch (match) {
     case ITEM_ID:
       return "vnd.android.cursor.item/item";
   }
   return null;
 }
 public static boolean isValidUri(String uri) {
   if (TextUtils.isEmpty(uri)) return false;
   Uri parsed = Uri.parse(uri);
   return parsed != null
       && !TextUtils.isEmpty(parsed.getAuthority())
       && !TextUtils.isEmpty(parsed.getHost())
       && !TextUtils.isEmpty(parsed.getScheme())
       && ("imap+ssl+".equalsIgnoreCase(parsed.getScheme())
           || "imap+ssl".equalsIgnoreCase(parsed.getScheme())
           || "imap".equalsIgnoreCase(parsed.getScheme())
           || "imap+tls+".equalsIgnoreCase(parsed.getScheme())
           || "imap+tls".equalsIgnoreCase(parsed.getScheme()));
 }
  public void activityResult(int requestCode, int resultCode, Intent data) {
    // 判断是否操作的当前的控件,如果不是直接返回。
    if (this.tag != CURRENT_TAG) return;

    if (requestCode == FLAG_CHOOSE_IMG && resultCode == Activity.RESULT_OK) { // 选择图片
      if (data != null) {
        Uri uri = data.getData();
        if (!TextUtils.isEmpty(uri.getAuthority())) {
          Cursor cursor =
              context
                  .getContentResolver()
                  .query(uri, new String[] {MediaStore.Images.Media.DATA}, null, null, null);
          if (null == cursor) {
            Toast.makeText(context, "图片没找到", Toast.LENGTH_SHORT).show();
            return;
          }
          cursor.moveToFirst();
          String path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA));
          cursor.close();
          Log.i("===", "path=" + path);
          Intent intent = new Intent(context, CropImageActivity.class);
          intent.putExtra("path", path);
          context.startActivityForResult(intent, FLAG_MODIFY_FINISH);
        } else {
          Log.i("===", "path=" + uri.getPath());
          Intent intent = new Intent(context, CropImageActivity.class);
          intent.putExtra("path", uri.getPath());
          context.startActivityForResult(intent, FLAG_MODIFY_FINISH);
        }
      }
    } else if (requestCode == FLAG_CHOOSE_PHONE && resultCode == Activity.RESULT_OK) { // 拍照
      File f = new File(FILE_PIC_SCREENSHOT, localTempImageFileName);
      Intent intent = new Intent(context, CropImageActivity.class);
      intent.putExtra("path", f.getAbsolutePath());
      context.startActivityForResult(intent, FLAG_MODIFY_FINISH);

    } else if (requestCode == FLAG_MODIFY_FINISH && resultCode == Activity.RESULT_OK) {
      if (data != null) {
        final String path = data.getStringExtra("path");
        Log.i("===", "截取到的图片路径是 = " + path);

        Bitmap b = BitmapFactory.decodeFile(path);

        headerImageStr = bitmap2Base64(b);

        if (this.listener != null) {
          this.listener.uploadImage(headerImageStr);
        }
      }
    }
  }
 public static boolean handleMedia(Context ctx, Uri mediaUri) {
   if (mediaUri.getScheme().equals("file")) {
     Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
     if (mediaUri.getLastPathSegment().endsWith("3gp")) {
       intent.setDataAndType(mediaUri, "video/3gpp");
       ctx.startActivity(intent);
       return true;
     } else if (mediaUri.getLastPathSegment().endsWith("jpg")) {
       // <scheme>://<authority><absolute path>
       Uri.Builder builder = new Uri.Builder();
       mediaUri =
           builder
               .scheme(mediaUri.getScheme())
               .authority(mediaUri.getAuthority())
               .path(mediaUri.getPath())
               .build();
       intent.setDataAndType(mediaUri, "image/jpeg");
       ctx.startActivity(intent);
       return true;
     } else if (mediaUri.getLastPathSegment().endsWith("txt")) {
       intent.setDataAndType(mediaUri, "text/plain");
       ctx.startActivity(intent);
       return true;
     }
   } else if (mediaUri.getScheme().equals("content")) {
     if (mediaUri.getAuthority().equals(GPStracking.AUTHORITY + ".string")) {
       String text = mediaUri.getLastPathSegment();
       Toast toast = Toast.makeText(ctx, text, Toast.LENGTH_LONG);
       toast.show();
       return true;
     } else if (mediaUri.getAuthority().equals("media")) {
       ctx.startActivity(new Intent(Intent.ACTION_VIEW, mediaUri));
       return true;
     }
   }
   return false;
 }
 private Uri convertToAndroidUriAndFixScheme(URI uri, URI uri1) {
   label0:
   {
     Uri uri2 = Uri.parse(uri.toString());
     uri = uri2;
     if (!"comgooglewallet".equals(uri2.getScheme())) {
       break label0;
     }
     if (uri1.getAuthority() != null) {
       uri = uri2;
       if (!uri1.getAuthority().isEmpty()) {
         break label0;
       }
     }
     if (uri2.getAuthority() != null) {
       uri = uri2;
       if (!uri2.getAuthority().isEmpty()) {
         break label0;
       }
     }
     uri = uri2.buildUpon().authority("").build();
   }
   return uri;
 }
 @Override
 public Cursor query(
     Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
   if (uri.getAuthority().contains("io.github.jhcpokemon.democontainer")) {
     Toast.makeText(getContext(), "Get Content", Toast.LENGTH_SHORT).show();
   }
   SQLiteDatabase.CursorFactory cursor =
       new SQLiteDatabase.CursorFactory() {
         @Override
         public Cursor newCursor(
             SQLiteDatabase db,
             SQLiteCursorDriver masterQuery,
             String editTable,
             SQLiteQuery query) {
           return null;
         }
       };
   return cursor.newCursor(null, null, null, null);
 }
    @Override
    public Response load(Uri uri, boolean localCacheOnly) throws IOException {
      Downloader downloader = null;

      String scheme = uri.getScheme();

      if (SCHEME_IMAGE.equals(scheme)) {
        String authority = uri.getAuthority();

        if (APPLICATION_AUTHORITY.equals(authority)) {
          downloader = appDownloader;
        } else if (ALBUM_AUTHORITY.equals(authority)) {
          downloader = albumDownloader;
        }
      } else {
        downloader = urlDownloader;
      }

      return downloader != null ? downloader.load(uri, localCacheOnly) : null;
    }
  @TargetApi(Build.VERSION_CODES.LOLLIPOP)
  private String getAbsolutePathFromFolderPickerResultUri(Uri resultUri) {
    if ("com.android.externalstorage.documents".equals(resultUri.getAuthority())) {
      final String documentId = DocumentsContract.getTreeDocumentId(resultUri);
      final String[] idParts = documentId.split(":"); // e.g. "primary:Podcasts"
      // Default: internal storage
      String rootPath = Environment.getExternalStorageDirectory().getAbsolutePath();

      // If not on internal storage -> SD card
      if (!"primary".equals(idParts[0]))
        // Make sure there is only one storage besides the internal one (i.e. the SD card),
        // other setups are just too complicated and rare for us to care about
        if (getExternalMediaDirs().length == 2)
          // Set root path to absolute path for SD card
          rootPath = getExternalMediaDirs()[1].getAbsolutePath().split("/Android")[0];
        else throw new IllegalArgumentException("Unknown storage setup");

      return rootPath + File.separator + idParts[1];
    } else throw new IllegalArgumentException("Not a real local folder");
  }
  // This is a hack before we find a solution to pass a permission to other
  // applications. See bug #1735149, #1836138.
  // Checks if the URI is on our whitelist:
  // content://media/... (MediaProvider)
  // file:///sdcard/... (Browser download)
  public static boolean isWhiteListUri(Uri uri) {
    if (uri == null) return false;

    String scheme = uri.getScheme();
    String authority = uri.getAuthority();

    if (scheme.equals("content") && authority.equals("media")) {
      return true;
    }

    if (scheme.equals("file")) {
      List<String> p = uri.getPathSegments();

      if (p.size() >= 1 && p.get(0).equals("sdcard")) {
        return true;
      }
    }

    return false;
  }
  /**
   * Implementation is provided by the parent class. Can be overridden to provide additional
   * functionality, but subclasses <em>must</em> always call the superclass. If the superclass
   * returns {@code null}, the subclass may implement custom behavior.
   */
  @Override
  public Bundle call(@NonNull String method, String arg, Bundle extras) {
    if (!method.startsWith("android:")) {
      // Ignore non-platform methods
      return super.call(method, arg, extras);
    }

    final Uri documentUri =
        extras.getParcelable(io.noobdev.neuteredsaf.compat.DocumentsContractCompat.EXTRA_URI);
    final String authority = documentUri.getAuthority();
    final String documentId =
        io.noobdev.neuteredsaf.compat.DocumentsContractCompat.getDocumentId(documentUri);

    if (!mAuthority.equals(authority)) {
      throw new SecurityException(
          "Requested authority " + authority + " doesn't match provider " + mAuthority);
    }
    enforceTree(documentUri);

    final Bundle out = new Bundle();
    try {
      if (METHOD_CREATE_DOCUMENT.equals(method)) {
        final String mimeType = extras.getString(Document.COLUMN_MIME_TYPE);
        final String displayName = extras.getString(Document.COLUMN_DISPLAY_NAME);
        final String newDocumentId = createDocument(documentId, mimeType, displayName);

        // No need to issue new grants here, since caller either has
        // manage permission or a prefix grant. We might generate a
        // tree style URI if that's how they called us.
        final Uri newDocumentUri = buildDocumentUriMaybeUsingTree(documentUri, newDocumentId);
        out.putParcelable(
            io.noobdev.neuteredsaf.compat.DocumentsContractCompat.EXTRA_URI, newDocumentUri);

      } else {
        throw new UnsupportedOperationException("Method not supported " + method);
      }
    } catch (FileNotFoundException e) {
      throw new IllegalStateException("Failed call " + method, e);
    }
    return out;
  }
    @Override
    protected RawContactDeltaList doInBackground(Intent... params) {

      final Intent intent = params[0];

      final ContentResolver resolver = activityTarget.getContentResolver();

      // Handle both legacy and new authorities
      final Uri data = intent.getData();
      final String authority = data.getAuthority();
      final String mimeType = intent.resolveType(resolver);

      mSelection = "0";
      String selectionArg = null;
      if (ContactsContract.AUTHORITY.equals(authority)) {
        if (Contacts.CONTENT_ITEM_TYPE.equals(mimeType)) {
          // Handle selected aggregate
          final long contactId = ContentUris.parseId(data);
          selectionArg = String.valueOf(contactId);
          mSelection = RawContacts.CONTACT_ID + "=?";
        } else if (RawContacts.CONTENT_ITEM_TYPE.equals(mimeType)) {
          final long rawContactId = ContentUris.parseId(data);
          final long contactId = queryForContactId(resolver, rawContactId);
          selectionArg = String.valueOf(contactId);
          mSelection = RawContacts.CONTACT_ID + "=?";
        }
      } else if (android.provider.Contacts.AUTHORITY.equals(authority)) {
        final long rawContactId = ContentUris.parseId(data);
        selectionArg = String.valueOf(rawContactId);
        mSelection = Data.RAW_CONTACT_ID + "=?";
      }

      // Note that this query does not need to concern itself with whether the contact is
      // the user's profile, since the profile does not show up in the picker.
      return RawContactDeltaList.fromQuery(
          RawContactsEntity.CONTENT_URI,
          activityTarget.getContentResolver(),
          mSelection,
          new String[] {selectionArg},
          null);
    }
Example #28
0
    @Override
    public void doConnectionHandover(NdefMessage handoverRequest, int handover, int record)
        throws IOException {

      byte[] remoteCollision = handoverRequest.getRecords()[handover + 1].getPayload();
      if (remoteCollision[0] == mCollisionResolution[0]
          && remoteCollision[1] == mCollisionResolution[1]) {
        return; // They'll have to try again.
      }
      boolean amServer =
          (remoteCollision[0] < mCollisionResolution[0]
              || (remoteCollision[0] == mCollisionResolution[0]
                  && remoteCollision[1] < mCollisionResolution[1]));

      if (mAlwaysClient) {
        amServer = false;
      }

      if (!mConnectionStarted) {
        synchronized (BluetoothConnecting.this) {
          if (!mConnectionStarted) {
            mConnectionStarted = true;
            mmBtConnected.beforeConnect(amServer);
          }
        }
      }
      if (!amServer) {
        // Not waiting for a connection:
        mAcceptThread.cancel();
        Uri uri = Uri.parse(new String(handoverRequest.getRecords()[record].getPayload()));
        UUID serviceUuid = UUID.fromString(uri.getPath().substring(1));
        int channel = -1;
        String channelStr = uri.getQueryParameter("channel");
        if (null != channelStr) {
          channel = Integer.parseInt(channelStr);
        }

        BluetoothDevice remoteDevice = mBluetoothAdapter.getRemoteDevice(uri.getAuthority());
        new ConnectThread(remoteDevice, serviceUuid, channel).start();
      }
    }
  /**
   * Returns true if the user has disabled sharing their location with url (e.g. via the geolocation
   * infobar). If the user has not chosen a preference for url and url uses the https scheme, this
   * considers the user's preference for url with the http scheme instead.
   */
  public static boolean isLocationDisabledForUrl(Uri uri) {
    // TODO(finnur): Delete this method once GeolocationHeader has been upstreamed.
    GeolocationInfo locationSettings = new GeolocationInfo(uri.toString(), null);
    ContentSetting locationPermission = locationSettings.getContentSetting();

    // If no preference has been chosen and the scheme is https, fall back to the preference for
    // this same host over http with no explicit port number.
    if (locationPermission == null || locationPermission == ContentSetting.ASK) {
      String scheme = uri.getScheme();
      if (scheme != null
          && scheme.toLowerCase(Locale.US).equals("https")
          && uri.getAuthority() != null
          && uri.getUserInfo() == null) {
        String urlWithHttp = "http://" + uri.getHost();
        locationSettings = new GeolocationInfo(urlWithHttp, null);
        locationPermission = locationSettings.getContentSetting();
      }
    }

    return locationPermission == ContentSetting.BLOCK;
  }
Example #30
0
 // 获取图片路径 响应startActivityForResult
 public void onActivityResult(int requestCode, int resultCode, Intent data) {
   super.onActivityResult(requestCode, resultCode, data);
   // 打开图片
   if (resultCode == getActivity().RESULT_OK && requestCode == IMAGE_OPEN) {
     Uri uri = data.getData();
     if (!TextUtils.isEmpty(uri.getAuthority())) {
       // 查询选择图片
       Cursor cursor =
           getActivity()
               .getContentResolver()
               .query(uri, new String[] {MediaStore.Images.Media.DATA}, null, null, null);
       // 返回 没找到选择图片
       if (null == cursor) {
         return;
       }
       // 光标移动至开头 获取图片路径
       cursor.moveToFirst();
       pathImage = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA));
     }
   } // end if 打开图片
 }