Java Code Examples for android.net.Uri#withAppendedPath()

The following examples show how to use android.net.Uri#withAppendedPath() . 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: LoginActivity.java    From android-test-demo with MIT License 6 votes vote down vote up
@Override
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
    return new CursorLoader(this,
            // Retrieve data rows for the device user's 'profile' contact.
            Uri.withAppendedPath(ContactsContract.Profile.CONTENT_URI,
                    ContactsContract.Contacts.Data.CONTENT_DIRECTORY), ProfileQuery.PROJECTION,

            // Select only email addresses.
            ContactsContract.Contacts.Data.MIMETYPE +
                    " = ?", new String[]{ContactsContract.CommonDataKinds.Email
                                                                 .CONTENT_ITEM_TYPE},

            // Show primary email addresses first. Note that there won't be
            // a primary email address if the user hasn't specified one.
            ContactsContract.Contacts.Data.IS_PRIMARY + " DESC");
}
 
Example 2
Source File: LoginActivity.java    From Pioneer with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
    return new CursorLoader(this,
            // Retrieve data rows for the device user's 'profile' contact.
            Uri.withAppendedPath(ContactsContract.Profile.CONTENT_URI,
                    ContactsContract.Contacts.Data.CONTENT_DIRECTORY), ProfileQuery.PROJECTION,

            // Select only email addresses.
            ContactsContract.Contacts.Data.MIMETYPE +
                    " = ?", new String[]{ContactsContract.CommonDataKinds.Email
            .CONTENT_ITEM_TYPE},

            // Show primary email addresses first. Note that there won't be
            // a primary email address if the user hasn't specified one.
            ContactsContract.Contacts.Data.IS_PRIMARY + " DESC");
}
 
Example 3
Source File: ContactPhotoQuery.java    From flutter_sms with MIT License 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.ECLAIR)
private void queryContactThumbnail() {
  Uri uri = Uri.withAppendedPath(ContactsContract.AUTHORITY_URI, photoUri);
  Cursor cursor = registrar.context().getContentResolver().query(uri,
      new String[]{ContactsContract.CommonDataKinds.Photo.PHOTO}, null, null, null);
  if (cursor == null) {
    return;
  }
  try {
    if (cursor.moveToFirst()) {
      result.success(cursor.getBlob(0));
    }
  } finally {
    cursor.close();
  }
}
 
Example 4
Source File: WidgetExpense.java    From fingen with Apache License 2.0 6 votes vote down vote up
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    // There may be multiple widgets active, so update all of them

    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_expense);
    Intent configIntent = new Intent(context, ActivityEditTransaction.class);
    Transaction transaction = new Transaction(PrefUtils.getDefDepID(context));
    transaction.setTransactionType(Transaction.TRANSACTION_TYPE_EXPENSE);
    configIntent.putExtra("transaction", transaction);
    configIntent.putExtra("update_date", true);
    configIntent.putExtra("EXIT", true);
    configIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    Uri data = Uri.withAppendedPath(Uri.parse("ABCD" + "://widget/id/"),String.valueOf(appWidgetIds[0]));
    configIntent.setData(data);

    PendingIntent configPendingIntent = PendingIntent.getActivity(context, 0, configIntent, 0);

    remoteViews.setOnClickPendingIntent(R.id.widgetContainer, configPendingIntent);
    appWidgetManager.updateAppWidget(appWidgetIds, remoteViews);
}
 
Example 5
Source File: PluginElement.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Launches an Intent to capture data captured using this element's plug-in.
 */
protected void capture() {
    try {
        Uri obs = Uri.withAppendedPath(getProcedure().getInstanceUri(), id);


        Intent plugin = new Intent(getAction());
        plugin.putExtras(getControlParams());
        plugin.putExtra(Observations.Contract.ID, id);
        plugin.putExtra(Observations.Contract.CONCEPT, concept);
        Log.d(TAG, "obs: " + obs);
        Intent i = new Intent(getContext(), ProcedureRunner.class);
        i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
                .putExtra(ProcedureRunner.INTENT_KEY_STRING,
                        ProcedureRunner.PLUGIN_INTENT_REQUEST_CODE)
                .putExtra(Observations.Contract.ID, id)
                .putExtra(Intent.EXTRA_INTENT, plugin)
                .setDataAndType(getProcedure().getInstanceUri(), mimeType);
        ((Activity) getContext()).startActivity(i);
    } catch (Exception e) {
        Log.e(TAG, "Error starting plugin: " + e.toString());
    }
}
 
Example 6
Source File: BindSampleContentProvider.java    From kripton with Apache License 2.0 6 votes vote down vote up
/**
 *
 * <h2>Supported insert operations</h2>
 * <table>
 * <tr><th>URI</th><th>DAO.METHOD</th></tr>
 * <tr><td><pre>content://com.abubusoft.contentprovidersample.provider/cheese</pre></td><td>{@link CheeseDaoImpl#insert0ForContentProvider}</td></tr>
 * </table>
 *
 */
@Override
public Uri insert(Uri uri, ContentValues contentValues) {
  long _id=-1;
  Uri _returnURL=null;
  switch (sURIMatcher.match(uri)) {
    case PATH_CHEESE_1_INDEX: {
      _id=dataSource.getCheeseDao().insert0ForContentProvider(uri, contentValues);
      _returnURL=Uri.withAppendedPath(uri, String.valueOf(_id));
      break;
    }
    default: {
      throw new IllegalArgumentException("Unknown URI for INSERT operation: " + uri);
    }
  }
  // log section for content provider insert BEGIN
  if (dataSource.isLogEnabled()) {
    Logger.info("Element is created with URI '%s'", _returnURL);
    Logger.info("Changes are notified for URI '%s'", uri);
  }
  // log section for content provider insert END
  getContext().getContentResolver().notifyChange(uri, null);
  return _returnURL;
}
 
Example 7
Source File: ModCallRecording.java    From XCallRecording-xposed with GNU General Public License v3.0 6 votes vote down vote up
String getContactName(Context context, String number) {
	if (null == context || TextUtils.isEmpty(number)) {
		return null;
	}
	Uri lookupUri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
	Cursor cursor = null;
	try {
		cursor = context.getContentResolver().query(lookupUri, new String[] {ContactsContract.PhoneLookup.DISPLAY_NAME}, null, null, null);
		if (null == cursor || cursor.getCount() == 0) {
			return null;
		}
		cursor.moveToNext();
		String name = cursor.getString(cursor.getColumnIndex(ContactsContract.PhoneLookup.DISPLAY_NAME));
		return name;
	} finally {
		if (null != cursor) {
			cursor.close();
		}
	}
}
 
Example 8
Source File: DownloadInfo.java    From mobile-manager-tool with MIT License 6 votes vote down vote up
private void readRequestHeaders(DownloadInfo info) {
    info.mRequestHeaders.clear();
    Uri headerUri = Uri.withAppendedPath(
            info.getAllDownloadsUri(), Downloads.RequestHeaders.URI_SEGMENT);
    Cursor cursor = mResolver.query(headerUri, null, null, null, null);
    try {
        int headerIndex =
                cursor.getColumnIndexOrThrow(Downloads.RequestHeaders.COLUMN_HEADER);
        int valueIndex =
                cursor.getColumnIndexOrThrow(Downloads.RequestHeaders.COLUMN_VALUE);
        for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
            addHeader(info, cursor.getString(headerIndex), cursor.getString(valueIndex));
        }
    } finally {
        cursor.close();
    }

    if (info.mCookies != null) {
        addHeader(info, "Cookie", info.mCookies);
    }
    if (info.mReferer != null) {
        addHeader(info, "Referer", info.mReferer);
    }
}
 
Example 9
Source File: OSUtilities.java    From Yahala-Messenger with MIT License 5 votes vote down vote up
public static Uri getMediaUri(String ringtoneTitle) {

        Uri parcialUri = Uri.parse("content://media/external/audio/media"); // also can be "content://media/internal/audio/media", depends on your needs
        Uri finalSuccessfulUri;

        RingtoneManager rm = new RingtoneManager(ApplicationLoader.applicationContext);
        rm.setType(RingtoneManager.TYPE_ALL);

        Cursor cursor = rm.getCursor();
        cursor = ApplicationLoader.applicationContext.getContentResolver().query(
                MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
                null,
                null,
                null,
                MediaStore.Audio.Media.TITLE);
        cursor.moveToFirst();

        while (!cursor.isAfterLast()) {
            // FileLog.e("finalSuccessfulUri",cursor.getString(cursor.getColumnIndex(MediaStore.MediaColumns.TITLE)));
            if (ringtoneTitle.equalsIgnoreCase(cursor.getString(cursor.getColumnIndex(MediaStore.MediaColumns.TITLE)))) {
                int ringtoneID = cursor.getInt(cursor.getColumnIndex(MediaStore.MediaColumns._ID));

                finalSuccessfulUri = Uri.withAppendedPath(parcialUri, "" + ringtoneID);
                // FileLog.e("finalSuccessfulUri",finalSuccessfulUri.getPath());
                return finalSuccessfulUri;
            }
            cursor.moveToNext();
        }
        return null;
    }
 
Example 10
Source File: NewContactsHelper.java    From callerid-for-android with GNU General Public License v3.0 5 votes vote down vote up
public boolean haveContactWithPhoneNumber(String phoneNumber) {
	final Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber));
	final ContentResolver contentResolver = application.getContentResolver();
	final Cursor cursor = contentResolver.query(uri,HAVE_CONTACT_PROJECTION,null,null,null);
	try{
		return cursor.moveToNext();
	}finally{
		cursor.close();
	}
}
 
Example 11
Source File: EmailHelper.java    From q-municate-android with Apache License 2.0 5 votes vote down vote up
public static List<InviteFriend> getContactsWithEmail(Context context) {
    List<InviteFriend> friendsContactsList = new ArrayList<InviteFriend>();
    Uri uri = null;

    ContentResolver contentResolver = context.getContentResolver();

    String[] PROJECTION = new String[]{ContactsContract.RawContacts._ID, ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.Contacts.PHOTO_ID, ContactsContract.CommonDataKinds.Email.DATA, ContactsContract.CommonDataKinds.Photo.CONTACT_ID};

    String order = "upper("+ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + ") ASC";

    String filter = ContactsContract.CommonDataKinds.Email.DATA + " NOT LIKE ''";

    Cursor cursor = contentResolver.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, PROJECTION,
            filter, null, order);

    if (cursor != null && cursor.moveToFirst()) {
        String id;
        String name;
        String email;
        do {
            name = cursor.getString(cursor.getColumnIndex(
                    ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
            email = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
            id = cursor.getString(cursor.getColumnIndex(
                    ContactsContract.CommonDataKinds.Phone.CONTACT_ID));
            if (ContactsContract.Contacts.CONTENT_URI != null) {
                uri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, Long.parseLong(
                        id));
                uri = Uri.withAppendedPath(uri, ContactsContract.Contacts.Photo.CONTENT_DIRECTORY);
            }
            friendsContactsList.add(new InviteFriend(email, name, null, InviteFriend.VIA_CONTACTS_TYPE,
                    uri, false));
        } while (cursor.moveToNext());
    }
    if (cursor != null) {
        cursor.close();
    }

    return friendsContactsList;
}
 
Example 12
Source File: Contacts.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Set the photo for this person. data may be null
 * @param cr the ContentResolver to use
 * @param person the Uri of the person whose photo is to be updated
 * @param data the byte[] that represents the photo
 * @deprecated see {@link android.provider.ContactsContract}
 */
@Deprecated
public static void setPhotoData(ContentResolver cr, Uri person, byte[] data) {
    Uri photoUri = Uri.withAppendedPath(person, Contacts.Photos.CONTENT_DIRECTORY);
    ContentValues values = new ContentValues();
    values.put(Photos.DATA, data);
    cr.update(photoUri, values, null, null);
}
 
Example 13
Source File: ContactAccessorSdk5.java    From cordova-android-chromeview with Apache License 2.0 5 votes vote down vote up
/**
 * Create a ContactField JSONObject
 * @param contactId
 * @return a JSONObject representing a ContactField
 */
private JSONObject photoQuery(Cursor cursor, String contactId) {
    JSONObject photo = new JSONObject();
    try {
        photo.put("id", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Photo._ID)));
        photo.put("pref", false);
        photo.put("type", "url");
        Uri person = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, (new Long(contactId)));
        Uri photoUri = Uri.withAppendedPath(person, ContactsContract.Contacts.Photo.CONTENT_DIRECTORY);
        photo.put("value", photoUri.toString());
    } catch (JSONException e) {
        Log.e(LOG_TAG, e.getMessage(), e);
    }
    return photo;
}
 
Example 14
Source File: BindPersonContentProvider.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 *
 * <h2>Supported insert operations</h2>
 * <table>
 * <tr><th>URI</th><th>DAO.METHOD</th></tr>
 * <tr><td><pre>content://sqlite.feature.contentprovider.kripton35/cities</pre></td><td>{@link CityDAOImpl#insertBean0ForContentProvider}</td></tr>
 * <tr><td><pre>content://sqlite.feature.contentprovider.kripton35/persons</pre></td><td>{@link PersonDAOImpl#insertBean0ForContentProvider}</td></tr>
 * <tr><td><pre>content://sqlite.feature.contentprovider.kripton35/persons/${name}</pre></td><td>{@link PersonDAOImpl#insertName1ForContentProvider}</td></tr>
 * </table>
 *
 */
@Override
public Uri insert(Uri uri, ContentValues contentValues) {
  long _id=-1;
  Uri _returnURL=null;
  switch (sURIMatcher.match(uri)) {
    case PATH_CITY_1_INDEX: {
      _id=dataSource.getCityDAO().insertBean0ForContentProvider(uri, contentValues);
      _returnURL=Uri.withAppendedPath(uri, String.valueOf(_id));
      break;
    }
    case PATH_PERSON_3_INDEX: {
      _id=dataSource.getPersonDAO().insertBean0ForContentProvider(uri, contentValues);
      _returnURL=Uri.withAppendedPath(uri, String.valueOf(_id));
      break;
    }
    case PATH_PERSON_5_INDEX: {
      _id=dataSource.getPersonDAO().insertName1ForContentProvider(uri, contentValues);
      _returnURL=Uri.withAppendedPath(uri, String.valueOf(_id));
      break;
    }
    default: {
      throw new IllegalArgumentException("Unknown URI for INSERT operation: " + uri);
    }
  }
  // log section for content provider insert BEGIN
  if (dataSource.isLogEnabled()) {
    Logger.info("Element is created with URI '%s'", _returnURL);
    Logger.info("Changes are notified for URI '%s'", uri);
  }
  // log section for content provider insert END
  getContext().getContentResolver().notifyChange(uri, null);
  return _returnURL;
}
 
Example 15
Source File: BindUserContentProvider.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 *
 * <h2>Supported insert operations</h2>
 * <table>
 * <tr><th>URI</th><th>DAO.METHOD</th></tr>
 * <tr><td><pre>content://sqlite.feature.pkstring.rx/user/insert1</pre></td><td>{@link UserDaoImpl#insertUser0ForContentProvider}</td></tr>
 * <tr><td><pre>content://sqlite.feature.pkstring.rx/user/insert2</pre></td><td>{@link UserDaoImpl#insertUser1ForContentProvider}</td></tr>
 * </table>
 *
 */
@Override
public Uri insert(Uri uri, ContentValues contentValues) {
  long _id=-1;
  Uri _returnURL=null;
  switch (sURIMatcher.match(uri)) {
    case PATH_USER_1_INDEX: {
      _id=dataSource.getUserDao().insertUser0ForContentProvider(uri, contentValues);
      _returnURL=Uri.withAppendedPath(uri, String.valueOf(_id));
      break;
    }
    case PATH_USER_2_INDEX: {
      _id=dataSource.getUserDao().insertUser1ForContentProvider(uri, contentValues);
      _returnURL=Uri.withAppendedPath(uri, String.valueOf(_id));
      break;
    }
    default: {
      throw new IllegalArgumentException("Unknown URI for INSERT operation: " + uri);
    }
  }
  // log section for content provider insert BEGIN
  if (dataSource.isLogEnabled()) {
    Logger.info("Element is created with URI '%s'", _returnURL);
    Logger.info("Changes are notified for URI '%s'", uri);
  }
  // log section for content provider insert END
  getContext().getContentResolver().notifyChange(uri, null);
  return _returnURL;
}
 
Example 16
Source File: doctorContract.java    From Doctorave with MIT License 4 votes vote down vote up
public static Uri contentUri(String username){
    String pathPatient = "[" + "patients" + username + "]";
    Uri uri = Uri.withAppendedPath(BASE_CONTENT_URI, pathPatient);
    return uri;
}
 
Example 17
Source File: PartAuthority.java    From bcm-android with GNU General Public License v3.0 4 votes vote down vote up
public static @NonNull Uri getAttachmentDataUri(long rowId, long uniqueId) {
    Uri uri = Uri.withAppendedPath(PART_CONTENT_URI, String.valueOf(uniqueId));
    return ContentUris.withAppendedId(uri, rowId);
}
 
Example 18
Source File: MultiDeviceContactUpdateJob.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
private Optional<SignalServiceAttachmentStream> getSystemAvatar(@Nullable Uri uri) {
  if (uri == null) {
    return Optional.absent();
  }
  
  Uri displayPhotoUri = Uri.withAppendedPath(uri, ContactsContract.Contacts.Photo.DISPLAY_PHOTO);

  try {
    AssetFileDescriptor fd = context.getContentResolver().openAssetFileDescriptor(displayPhotoUri, "r");

    if (fd == null) {
      return Optional.absent();
    }

    return Optional.of(SignalServiceAttachment.newStreamBuilder()
                                              .withStream(fd.createInputStream())
                                              .withContentType("image/*")
                                              .withLength(fd.getLength())
                                              .build());
  } catch (IOException e) {
    Log.i(TAG, "Could not find avatar for URI: " + displayPhotoUri);
  }

  Uri photoUri = Uri.withAppendedPath(uri, ContactsContract.Contacts.Photo.CONTENT_DIRECTORY);

  if (photoUri == null) {
    return Optional.absent();
  }

  Cursor cursor = context.getContentResolver().query(photoUri,
                                                     new String[] {
                                                         ContactsContract.CommonDataKinds.Photo.PHOTO,
                                                         ContactsContract.CommonDataKinds.Phone.MIMETYPE
                                                     }, null, null, null);

  try {
    if (cursor != null && cursor.moveToNext()) {
      byte[] data = cursor.getBlob(0);

      if (data != null) {
        return Optional.of(SignalServiceAttachment.newStreamBuilder()
                                                  .withStream(new ByteArrayInputStream(data))
                                                  .withContentType("image/*")
                                                  .withLength(data.length)
                                                  .build());
      }
    }

    return Optional.absent();
  } finally {
    if (cursor != null) {
      cursor.close();
    }
  }
}
 
Example 19
Source File: PartAuthority.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
public static Uri getAttachmentThumbnailUri(AttachmentId attachmentId) {
  Uri uri = Uri.withAppendedPath(THUMB_CONTENT_URI, String.valueOf(attachmentId.getUniqueId()));
  return ContentUris.withAppendedId(uri, attachmentId.getRowId());
}
 
Example 20
Source File: PartProvider.java    From bcm-android with GNU General Public License v3.0 4 votes vote down vote up
public static @NonNull
Uri getGroupUri(long gid, long indexId) {
    Uri uri = Uri.withAppendedPath(GROUP_URI, String.valueOf(gid));
    return ContentUris.withAppendedId(uri, indexId);
}