Example usage for android.net Uri withAppendedPath

List of usage examples for android.net Uri withAppendedPath

Introduction

In this page you can find the example usage for android.net Uri withAppendedPath.

Prototype

public static Uri withAppendedPath(Uri baseUri, String pathSegment) 

Source Link

Document

Creates a new Uri by appending an already-encoded path segment to a base Uri.

Usage

From source file:com.google.android.apps.paco.NotificationCreator.java

private void createAlarmToCancelNotificationAtTimeout(Context context, NotificationHolder notificationHolder) {
    DateTime alarmTime = new DateTime(notificationHolder.getAlarmTime());
    int timeoutMinutes = (int) (notificationHolder.getTimeoutMillis() / MILLIS_IN_MINUTE);
    DateTime timeoutTime = new DateTime(alarmTime).plusMinutes(timeoutMinutes);
    long elapsedDurationInMillis = timeoutTime.getMillis();

    Log.i(PacoConstants.TAG,/*  w  w w. ja v  a  2 s.c  o m*/
            "Creating cancel alarm to timeout notification for holder: " + notificationHolder.getId()
                    + ". experiment = " + notificationHolder.getExperimentId() + ". alarmtime = "
                    + new DateTime(alarmTime).toString() + " timing out in " + timeoutMinutes + " minutes");

    Intent ultimateIntent = new Intent(context, AlarmReceiver.class);
    Uri uri = Uri.withAppendedPath(NotificationHolderColumns.CONTENT_URI,
            notificationHolder.getId().toString());
    ultimateIntent.setData(uri);
    ultimateIntent.putExtra(NOTIFICATION_ID, notificationHolder.getId().longValue());

    PendingIntent intent = PendingIntent.getBroadcast(context.getApplicationContext(), 2, ultimateIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    alarmManager.cancel(intent);
    alarmManager.set(AlarmManager.RTC_WAKEUP, elapsedDurationInMillis, intent);
}

From source file:com.hybris.mobile.lib.commerce.provider.CatalogProvider.java

/**
 * Insert/Update the out-of-date sync status for an element (data or group) and return true if the sync adapter needs
 * to be triggered/* w  w w . j  av  a  2s.c  om*/
 *
 * @param uriElement String of characters used to identify a name of a resource
 * @param idName     Unique name string
 * @param tableName  an element (data or group)
 * @param idElement  Unique element Identifier
 * @return true if the sync adapter needs to be triggered
 */
private boolean updateTrackSyncStatus(Uri uriElement, String idName, String tableName, String idElement) {

    boolean triggerSyncAdapter = true;

    ContentValues contentValues = new ContentValues();
    contentValues.put(idName, idElement);
    contentValues.put(CatalogContract.DataBaseSyncStatusGroup.ATT_STATUS, SyncStatus.OUTOFDATE.getValue());

    // Cursor to check if we need to trigger the sync adapter (data out-of-date)
    Cursor cursorCheckUpToDate = mDatabaseHelper.getReadableDatabase().query(tableName,
            new String[] { CatalogContract.DataBaseData.ATT_STATUS }, idName + "=?", new String[] { idElement },
            null, null, null);

    // Checking if we need to trigger the sync adapter
    if (cursorCheckUpToDate != null && cursorCheckUpToDate.getCount() > 0) {
        cursorCheckUpToDate.moveToFirst();

        // Sync status flag to out-of-date
        triggerSyncAdapter = (cursorCheckUpToDate.getInt(0) == SyncStatus.OUTOFDATE.getValue());

        cursorCheckUpToDate.close();
    }

    // Insert (or update) the row for the sync status out-to-date:
    // Case 1: we need to trigger the sync adapter
    // Case 2: the value is up-to-date, we invalidate the sync status for the next calls to the provider
    insert(Uri.withAppendedPath(uriElement, idElement), contentValues);

    return triggerSyncAdapter;
}

From source file:com.example.mydemos.view.RingtonePickerActivity.java

private void setDefaultRingtone() {
    final Uri musicDefault = MediaStore.Audio.Media.INTERNAL_CONTENT_URI;
    final String musicTitle = MediaStore.Audio.AudioColumns.TITLE;
    final String musicId = MediaStore.Audio.Media._ID;
    final String musicName = MediaStore.Audio.AudioColumns.DISPLAY_NAME;

    // Get a ContentResovler, 
    // so that we can read the music information form SD card.
    ContentResolver contentResolver = getContentResolver();
    Uri uri = null;/*  www .j  av  a  2 s  . c  om*/
    String ringtone = "AA_Preo_ringtone.ogg";
    Cursor cursor = contentResolver.query(musicDefault, new String[] { musicId, musicName },
            musicName + " LIKE ?", new String[] { ringtone }, null);
    // If cursor has a recode, we support that we find the music.
    if (cursor.moveToNext()) {
        // Get the music id.
        int position = cursor.getInt(cursor.getColumnIndex(musicId));
        uri = Uri.withAppendedPath(musicDefault, "/" + position);
        Log.d("test", uri.toString());
    }
    // Finish our query work.
    cursor.close();

    if (uri != null) {
        ContentValues values = new ContentValues();
        values.put(MediaStore.Audio.AudioColumns.ALBUM_ARTIST, "first");
        contentResolver.update(uri, values, null, null);
    }

    //        defaultView = getLayoutInflater().inflate(
    //              R.layout.tab_picker_item, listView, false);
    //        TextView textView = (TextView) defaultView.findViewById(R.id.title);
    //      textView.setText(musicName);
    //        listView.addHeaderView(defaultView, null, true);
    //        mStaticItemCount++;

}

From source file:android.com.example.contactslist.ui.ContactDetailFragment.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    switch (id) {
    // Two main queries to load the required information
    case ContactDetailQuery.QUERY_ID:
        // This query loads main contact details, see
        // ContactDetailQuery for more information.
        return new CursorLoader(getActivity(), mContactUri, ContactDetailQuery.PROJECTION, null, null, null);
    case ContactAddressQuery.QUERY_ID:
        // This query loads contact address details, see
        // ContactAddressQuery for more information.
        final Uri uri = Uri.withAppendedPath(mContactUri, Contacts.Data.CONTENT_DIRECTORY);
        return new CursorLoader(getActivity(), uri, ContactAddressQuery.PROJECTION,
                ContactAddressQuery.SELECTION, null, null);
    }/*from   w ww  .  j  ava2s .c  o m*/
    return null;
}

From source file:com.intel.xdk.contacts.Contacts.java

public void editContact(String contactId) {
    if (busy == true) {
        String js = "javascript: var e = document.createEvent('Events');e.initEvent('intel.xdk.contacts.busy',true,true);e.success=false;e.message='busy';document.dispatchEvent(e);";
        injectJS(js);//w w w  .  j  av  a  2 s .  c  o  m
        return;
    }

    try {
        //Determine if Contact ID exists
        Uri res = null;
        Uri lookupUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, contactId);

        try {
            res = ContactsContract.Contacts.lookupContact(activity.getContentResolver(), lookupUri);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (res != null) {
            busy = true;
            Intent intent = new Intent(Intent.ACTION_EDIT);
            contactBeingEdited = contactId;
            intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
            intent.setData(res);
            //launch activity
            cordova.setActivityResultCallback(this);
            activity.startActivityForResult(intent, CONTACT_EDIT_RESULT);
            //activity.setLaunchedChildActivity(true); 
        } else {
            contactBeingEdited = "";
            String errjs1 = String.format(
                    "var e = document.createEvent('Events');e.initEvent('intel.xdk.contacts.edit',true,true);e.success=false;e.error='contact not found';e.contactid='%s';document.dispatchEvent(e);",
                    contactId);
            injectJS("javascript: " + errjs1);
        }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:com.navjagpal.fileshare.WebServer.java

private void sendSharedFilesList(DefaultHttpServerConnection serverConnection, RequestLine requestLine)
        throws UnsupportedEncodingException, HttpException, IOException {
    HttpResponse response = new BasicHttpResponse(new HttpVersion(1, 1), 200, "OK");
    String folderId = getFolderId(requestLine.getUri());
    String header = getHTMLHeader();
    String form = getUploadForm(folderId);
    String footer = getHTMLFooter();
    String listing = getFileListing(Uri.withAppendedPath(FileSharingProvider.Folders.CONTENT_URI, folderId));
    response.setEntity(new StringEntity(header + listing + form + footer));
    serverConnection.sendResponseHeader(response);
    serverConnection.sendResponseEntity(response);
}

From source file:org.thoughtcrime.securesms.contacts.ContactAccessorNewApi.java

@Override
public String getNameForNumber(Context context, String number) {
    Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
    Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);

    try {//from  w  ww  . j a v  a  2 s  .  c o  m
        if (cursor != null && cursor.moveToFirst())
            return cursor.getString(cursor.getColumnIndexOrThrow(PhoneLookup.DISPLAY_NAME));
    } finally {
        if (cursor != null)
            cursor.close();
    }

    return null;
}

From source file:de.vanita5.twittnuker.provider.TwidereDataProvider.java

@Override
public Uri insert(final Uri uri, final ContentValues values) {
    try {/*from w  ww.j  a  v a 2 s  .c o  m*/
        final int tableId = getTableId(uri);
        final String table = getTableNameById(tableId);
        switch (tableId) {
        case TABLE_ID_DIRECT_MESSAGES_CONVERSATION:
        case TABLE_ID_DIRECT_MESSAGES:
        case TABLE_ID_DIRECT_MESSAGES_CONVERSATIONS_ENTRIES:
            return null;
        }
        if (table == null)
            return null;
        final long rowId;
        if (tableId == TABLE_ID_CACHED_USERS) {
            final Expression where = Expression.equals(CachedUsers.USER_ID,
                    values.getAsLong(CachedUsers.USER_ID));
            mDatabaseWrapper.update(table, values, where.getSQL(), null);
            rowId = mDatabaseWrapper.insertWithOnConflict(table, null, values, SQLiteDatabase.CONFLICT_IGNORE);
        } else if (tableId == TABLE_ID_SEARCH_HISTORY) {
            values.put(SearchHistory.RECENT_QUERY, System.currentTimeMillis());
            final Expression where = Expression.equalsArgs(SearchHistory.QUERY);
            final String[] args = { values.getAsString(SearchHistory.QUERY) };
            mDatabaseWrapper.update(table, values, where.getSQL(), args);
            rowId = mDatabaseWrapper.insertWithOnConflict(table, null, values, SQLiteDatabase.CONFLICT_IGNORE);
        } else if (tableId == TABLE_ID_CACHED_RELATIONSHIPS) {
            final long accountId = values.getAsLong(CachedRelationships.ACCOUNT_ID);
            final long userId = values.getAsLong(CachedRelationships.USER_ID);
            final Expression where = Expression.and(
                    Expression.equals(CachedRelationships.ACCOUNT_ID, accountId),
                    Expression.equals(CachedRelationships.USER_ID, userId));
            if (mDatabaseWrapper.update(table, values, where.getSQL(), null) > 0) {
                final String[] projection = { CachedRelationships._ID };
                final Cursor c = mDatabaseWrapper.query(table, projection, where.getSQL(), null, null, null,
                        null);
                if (c.moveToFirst()) {
                    rowId = c.getLong(0);
                } else {
                    rowId = 0;
                }
                c.close();
            } else {
                rowId = mDatabaseWrapper.insertWithOnConflict(table, null, values,
                        SQLiteDatabase.CONFLICT_IGNORE);
            }
        } else if (shouldReplaceOnConflict(tableId)) {
            rowId = mDatabaseWrapper.insertWithOnConflict(table, null, values, SQLiteDatabase.CONFLICT_REPLACE);
        } else {
            rowId = mDatabaseWrapper.insert(table, null, values);
        }
        onDatabaseUpdated(tableId, uri);
        onNewItemsInserted(uri, tableId, values, rowId);
        return Uri.withAppendedPath(uri, String.valueOf(rowId));
    } catch (final SQLException e) {
        throw new IllegalStateException(e);
    }
}

From source file:at.bitfire.davdroid.resource.LocalAddressBook.java

protected void populatePhoto(Contact c, ContentValues row) throws RemoteException {
    if (row.containsKey(Photo.PHOTO_FILE_ID)) {
        Uri photoUri = Uri.withAppendedPath(ContentUris.withAppendedId(RawContacts.CONTENT_URI, c.getLocalID()),
                RawContacts.DisplayPhoto.CONTENT_DIRECTORY);
        try {//from www. ja va2s.c o m
            @Cleanup
            AssetFileDescriptor fd = providerClient.openAssetFile(photoUri, "r");
            @Cleanup
            InputStream is = fd.createInputStream();
            c.photo = IOUtils.toByteArray(is);
        } catch (IOException ex) {
            Log.w(TAG, "Couldn't read high-res contact photo", ex);
        }
    } else
        c.photo = row.getAsByteArray(Photo.PHOTO);
}

From source file:at.bitfire.davdroid.mirakel.resource.LocalAddressBook.java

protected void populatePhoto(Contact c) throws RemoteException {
    @Cleanup/*from w w w  .  j av a  2s. c o  m*/
    Cursor cursor = providerClient.query(dataURI(), new String[] { Photo.PHOTO_FILE_ID, Photo.PHOTO },
            Photo.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
            new String[] { String.valueOf(c.getLocalID()), Photo.CONTENT_ITEM_TYPE }, null);
    if (cursor != null && cursor.moveToNext()) {
        if (!cursor.isNull(0)) {
            Uri photoUri = Uri.withAppendedPath(
                    ContentUris.withAppendedId(RawContacts.CONTENT_URI, c.getLocalID()),
                    RawContacts.DisplayPhoto.CONTENT_DIRECTORY);
            try {
                @Cleanup
                AssetFileDescriptor fd = providerClient.openAssetFile(photoUri, "r");
                @Cleanup
                InputStream is = fd.createInputStream();
                c.setPhoto(IOUtils.toByteArray(is));
            } catch (IOException ex) {
                Log.w(TAG, "Couldn't read high-res contact photo", ex);
            }
        } else
            c.setPhoto(cursor.getBlob(1));
    }
}