Android Uri - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android Uri class.

This code example shows how to use the following methods:query
  } 
 
  public static Bitmap getLocalUserContactPhoto(Context context, Uri uri) {
    if (uri == null) return getDefaultContactPhoto(context);
 
    Bitmap contactPhoto = localUserContactPhotoCache.get(uri);
 
    if (contactPhoto == null) {
      Cursor cursor = context.getContentResolver().query(uri, CONTENT_URI_PROJECTION,
                                                         null, null, null); 
 
      if (cursor != null && cursor.moveToFirst()) {
        contactPhoto = getContactPhoto(context, Uri.withAppendedPath(Contacts.CONTENT_URI,
                                       cursor.getLong(0) + ""));
      } else { 
        contactPhoto = getDefaultContactPhoto(context);
      } 
 
      localUserContactPhotoCache.put(uri, contactPhoto);
    } 

8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getAuthority, getPath, toString
        ctx.revokeUriPermission(Uri.parse(rootUri), Intent.FLAG_GRANT_READ_URI_PERMISSION);
    } 
     
    public static File fileFromUri(Uri uri) throws IllegalArgumentException
    { 
        String authority = uri.getAuthority();
        if(isCorrectAuthority(authority))
            return new File(PATH_PREFIX + authority + uri.getPath());
        else throw new IllegalArgumentException("Unknown URI authority: " + authority);
    } 
     
    @Override 
    public ParcelFileDescriptor openFile(Uri uri, String mode)
        throws FileNotFoundException, SecurityException 
    { 
        Logger.T(TAG, "Opening content: " + uri);
         
        if(mode.compareTo("r") != 0)
        { 
            throw new SecurityException("Unacceptable openFile mode: " + mode);

8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getPath, getScheme, toString
		InputStream stream = openInputStream( context, uri );
		if ( null == stream ) {
			return null; 
		} 
		 
		int orientation = ExifUtils.getExifOrientation( context, uri );
 
		Bitmap bitmap = null;
		int[] imageSize = new int[2];
		final boolean decoded = decodeImageBounds( stream, imageSize );
		IOUtils.closeSilently( stream );
 
		if ( decoded ) {
			int sampleSize;
			if( maxW < 0 || maxH < 0 ) {
				sampleSize = 1;
			} else { 
				sampleSize = computeSampleSize( imageSize[0], imageSize[1], (int) ( maxW * 1.2 ), (int) ( maxH * 1.2 ), orientation );
			} 
 

8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getQueryParameter
        @Override 
        protected Boolean doInBackground(Void... params)
        { 
            try 
            { 
                String oAuthConsumerKey = mUri
                        .getQueryParameter("oauth_consumer_key");
                String oAuthConsumerSecret = mUri
                        .getQueryParameter("oauth_consumer_secret");
                String oAuthToken = mUri.getQueryParameter("oauth_token");
                String oAuthTokenSecret = mUri
                        .getQueryParameter("oauth_token_secret");
                String oAuthVerifier = mUri.getQueryParameter("oauth_verifier");
 
                mUsedConsumer = new DefaultOAuthConsumer(oAuthConsumerKey,
                        oAuthConsumerSecret);
                mUsedConsumer.setTokenWithSecret(oAuthToken, oAuthTokenSecret);
 
                OAuthProvider provider = Preferences
                        .getOAuthProvider(activity);
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getLastPathSegment, isHierarchical
		return Uri.withAppendedPath(contentUri, String.valueOf(id));
	} 
 
	@Implementation 
	public static long parseId(Uri contentUri) {
		if (!contentUri.isHierarchical()) {
			throw new UnsupportedOperationException();
		} 
		String path = contentUri.getLastPathSegment();
		if (path == null) return -1;
		return Long.parseLong(path);
	} 
 
} 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:parseId, withAppendedPath
    public void appendIdThrowsNullPointerException() { 
        ContentUris.withAppendedId(null, 1);
    } 
 
    @Test public void canParseId() { 
        assertThat(ContentUris.parseId(Uri.withAppendedPath(URI, "1"))).isEqualTo(1L);
        assertThat(ContentUris.parseId(URI)).isEqualTo(-1L);
    } 
 
    @Test(expected = NumberFormatException.class) 
    public void parseIdThrowsNumberFormatException() { 
        ContentUris.parseId(Uri.withAppendedPath(URI, "bar"));
    } 
 
    @Test(expected = UnsupportedOperationException.class) 
    public void parseIdThrowsUnsupportedException() { 
        ContentUris.parseId(Uri.parse("mailto:bar@foo.com"));
    } 
 
} 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:parseId
  public InputStream getPartDataInputStream() throws FileNotFoundException {
    Uri partUri = part.getDataUri();
		 
    Log.w("Slide", "Loading Part URI: " + partUri);
		 
    if (PartProvider.isAuthority(partUri))
      return DatabaseFactory.getEncryptingPartDatabase(context, masterSecret).getPartStream(ContentUris.parseId(partUri));
    else 
      return context.getContentResolver().openInputStream(partUri);
  } 
	 
  protected static long getMediaSize(Context context, Uri uri) throws IOException {
    InputStream in = context.getContentResolver().openInputStream(uri);
    long size      = 0;
    byte[] buffer  = new byte[512];
    int read;
		 
    while ((read = in.read(buffer)) != -1)
      size += read;
		 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getAuthority, getHost, getScheme
        // 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));
    } 
 
    public IImage getImageForUri(Uri uri) {
        if (!isChildImageUri(uri)) return null;
        // Find the id of the input URI. 
        long matchId;
        try { 
            matchId = ContentUris.parseId(uri);
        } catch (NumberFormatException ex) {
            Log.i(TAG, "fail to get id in: " + uri, ex);
            return null; 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:toString
        return new _RingtonePickerDialog(getContext(), intent, this).makeDialog();
    } 
 
    @Override 
    protected void onDialogClosed(boolean positiveResult) {
        String uri = mLastUri == null ? "" : mLastUri.toString();
        if (positiveResult && callChangeListener(uri)) {
            persistString(uri);
        } 
    } 
 
    @Override 
    protected Object onGetDefaultValue(TypedArray a, int index) {
        return a.getString(index);
    } 
 
    protected void onPrepareRingtonePickerIntent(Intent ringtonePickerIntent) {
        ringtonePickerIntent.putExtra(
                RingtoneManager.EXTRA_RINGTONE_EXISTING_URI,
                onRestoreRingtone()); 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:withAppendedPath
	private String getContactNameFromNumber(String number) {
		// define the columns I want the query to return 
		String[] projection = new String[] { Contacts.Phones.DISPLAY_NAME, Contacts.Phones.NUMBER };
 
		// encode the phone number and build the filter URI 
		Uri contactUri = Uri.withAppendedPath(Contacts.Phones.CONTENT_FILTER_URL, Uri.encode(number));
 
		// query time 
		Cursor c = ctx.getContentResolver().query(contactUri, projection, null, null, null);
 
		// if the query returns 1 or more results 
		// return the first result 
		if (c.moveToFirst()) {
			String name = c.getString(c.getColumnIndex(Contacts.Phones.DISPLAY_NAME));
			c.deactivate();
			return name;
		} 
 
		// return the original number if no match was found 
		return number;
7
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Android Uri Questions & Answers:

Other Android Uri Examples

70:	    ContentResolver contentResolver = getContentResolver();
71:	
72:	    Uri base = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
73:	    Uri newUri = contentResolver.insert(base, values);
74:	
-
71:	
72:	    Uri base = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
73:	    Uri newUri = contentResolver.insert(base, values);
74:	
75:	    sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, newUri));

Read More

37:	  private Cursor getContacts() {
38:	    // Run query
39:	    Uri uri = ContactsContract.Contacts.CONTENT_URI;
40:	    String[] projection = new String[] { ContactsContract.Contacts._ID,
41:	        ContactsContract.Contacts.DISPLAY_NAME };

Read More

15:			 * */
16:			if (!isTwitterLoggedInAlready()) {
17:				Uri uri = getIntent().getData();
18:				if (uri != null && uri.toString().startsWith(TWITTER_CALLBACK_URL)) {
19:					// oAuth verifier

Read More

1:		 * Creating file uri to store image/video
2:		 */
3:		public Uri getOutputMediaFileUri(int type) {
4:			return Uri.fromFile(getOutputMediaFile(type));
5:		}

Read More

9:		private static final String IMAGE_DIRECTORY_NAME = "Hello Camera";
10:	
11:		private Uri fileUri; // file url to store image/video
12:	
13:		private ImageView imgPreview;

Read More

See Code Examples for Android Uri Methods: