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:net.dahanne.spring.android.ch3.restful.example.recipeapp.RecipesList.java

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {

    // The data from the menu item.
    AdapterView.AdapterContextMenuInfo info;

    // Tries to get the position of the item in the ListView that was long-pressed.
    try {/*from  www . j av a 2s . c  om*/
        // Casts the incoming data object into the type for AdapterView objects.
        info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    } catch (ClassCastException e) {
        // If the menu object can't be cast, logs an error.
        Log.e(TAG, "bad menuInfo", e);
        return;
    }
    Intent intent = new Intent(null,
            Uri.withAppendedPath(getIntent().getData(), Integer.toString((int) info.id)));
    intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
    menu.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0, new ComponentName(this, RecipesList.class), null,
            intent, 0, null);
}

From source file:com.securecomcode.text.contacts.ContactAccessor.java

public Collection<ContactData> getContactsWithPush(Context context) {
    final ContentResolver resolver = context.getContentResolver();
    final String[] inProjection = new String[] { PhoneLookup._ID, PhoneLookup.DISPLAY_NAME };

    List<String> pushNumbers = Directory.getInstance(context).getActiveNumbers();
    final Collection<ContactData> lookupData = new ArrayList<ContactData>(pushNumbers.size());

    for (String pushNumber : pushNumbers) {
        Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(pushNumber));
        Cursor lookupCursor = resolver.query(uri, inProjection, null, null, null);
        try {//w  ww . j  a  v  a2s. com
            if (lookupCursor != null && lookupCursor.moveToFirst()) {
                final ContactData contactData = new ContactData(lookupCursor.getLong(0),
                        lookupCursor.getString(1));
                contactData.numbers.add(new NumberData("TextSecure", pushNumber));
                lookupData.add(contactData);
            }
        } finally {
            if (lookupCursor != null)
                lookupCursor.close();
        }
    }
    return lookupData;
}

From source file:org.fourthline.android.feeds.FeedEntryDetailsActivity.java

@Override
protected void onPause() {
    super.onPause();
    log.fine("On pause, feed config change notification (we might have marked some entries as read)");
    // Unique feed config ids
    Set<Long> feedConfigIds = new HashSet<Long>();
    for (FeedEntryDetail detail : feedReader.feedEntryDetails.details) {
        feedConfigIds.add(detail.feedConfigId);
    }/*from ww  w.j ava 2  s . com*/
    for (Long feedConfigId : feedConfigIds) {
        Uri uri = Uri.withAppendedPath(FeedConfig.CONTENT_URI, String.valueOf(feedConfigId));
        getContentResolver().notifyChange(uri, null);
    }
}

From source file:edu.nd.darts.cimon.database.CimonDatabaseAdapter.java

/**
 * Insert new metric group into MetricInfo table, or replace if the id already exist.
 * /*from   w  w w. ja v a 2s. co  m*/
 * @param id             id which identifies metric group to insert
 * @param title          name of metric group
 * @param description    short description of metric
 * @param supported      metric support status on system [1-supported/0-not supported]
 * @param power          power used to monitor this metric (milliAmps)
 * @param mininterval    minimum possible interval between readings (milliseconds)
 * @param maxrange       maximum range measurable by metric, including units
 * @param resolution     resolution of measurements, including units
 * @param type           value representing metric type [system/sensor/user]
 * @return    rowid of inserted row, -1 on failure
 * 
 * @see MetricInfoTable
 */
public synchronized long insertOrReplaceMetricInfo(int id, String title, String description, int supported,
        float power, int mininterval, String maxrange, String resolution, int type) {
    if (DebugLog.DEBUG)
        Log.d(TAG, "CimonDatabaseAdapter.insertOrReplaceMetricInfo - insert into MetricInfo table: metric-"
                + title);
    ContentValues values = new ContentValues();
    values.put(MetricInfoTable.COLUMN_ID, id);
    values.put(MetricInfoTable.COLUMN_TITLE, title);
    values.put(MetricInfoTable.COLUMN_DESCRIPTION, description);
    values.put(MetricInfoTable.COLUMN_SUPPORTED, supported);
    values.put(MetricInfoTable.COLUMN_POWER, power);
    values.put(MetricInfoTable.COLUMN_MININTERVAL, mininterval);
    values.put(MetricInfoTable.COLUMN_MAXRANGE, maxrange);
    values.put(MetricInfoTable.COLUMN_RESOLUTION, resolution);
    values.put(MetricInfoTable.COLUMN_TYPE, type);
    //      SQLiteDatabase sqlDB = database.getWritableDatabase();
    long rowid = database.replace(MetricInfoTable.TABLE_METRICINFO, null, values);
    if (rowid >= 0) {
        Uri uri = Uri.withAppendedPath(CimonContentProvider.INFO_URI, String.valueOf(id));
        context.getContentResolver().notifyChange(uri, null);
        uri = Uri.withAppendedPath(CimonContentProvider.CATEGORY_URI, String.valueOf(type));
        context.getContentResolver().notifyChange(uri, null);
    }
    return rowid;
}

From source file:org.sociotech.fishification.ui.fragments.CreateFishFragment.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle bundle) {

    // Retrieve data rows for the device user's 'profile' contact.
    String[] projection = ProfileQuery.EMAIL_ADDRESS_PROJECTION;
    if (id == 0) {
        projection = ProfileQuery.DISPLAY_NAME_PROJECTION;
    }//ww w  .j a v a  2 s  . co  m

    // Get Cursor for primary E-Mail address
    return new CursorLoader(getActivity(),

            Uri.withAppendedPath(ContactsContract.Profile.CONTENT_URI,
                    ContactsContract.Contacts.Data.CONTENT_DIRECTORY),
            projection, ContactsContract.Contacts.Data.MIMETYPE + " = ?",

            // Select e-mail address item type
            new String[] { ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE },

            // Show primary name first
            ContactsContract.Contacts.Data.IS_PRIMARY + " DESC");

}

From source file:com.jaspersoft.android.jaspermobile.util.ProfileHelper.java

public void updateCurrentInfoSnapshot(long profileId, ServerInfo serverInfo) {
    Cursor cursor = queryServerProfile(profileId);
    if (cursor != null) {
        try {//from   w  ww . j  av a2 s  . c  om
            if (cursor.getCount() > 0) {
                cursor.moveToPosition(0);
                ServerProfiles profile = new ServerProfiles(cursor);
                profile.setVersioncode(serverInfo.getVersionCode());
                profile.setEdition(serverInfo.getEdition());

                Uri uri = Uri.withAppendedPath(JasperMobileDbProvider.SERVER_PROFILES_CONTENT_URI,
                        String.valueOf(profileId));
                context.getContentResolver().update(uri, profile.getContentValues(), null, null);
                serverInfoSnapshot.setProfile(profile);
            }
        } finally {
            cursor.close();
        }
    }
}

From source file:cz.maresmar.sfm.view.order.OrderFragment.java

@NonNull
@Override//from w  ww .jav a  2 s.  c  o  m
public Loader<Cursor> onCreateLoader(int id, @Nullable Bundle args) {
    switch (id) {
    case ACTION_LOADER_ID: {
        Uri actionsUri = Uri.withAppendedPath(mUserUri, ProviderContract.ACTION_PATH);
        return new CursorLoader(getContext(), actionsUri,
                new String[] { ProviderContract.Action._ID, ProviderContract.Action.ENTRY_TYPE,
                        ProviderContract.Action.SYNC_STATUS, ProviderContract.Action.ME_DATE,
                        ProviderContract.Action.PRICE, ProviderContract.Action.ME_PORTAL_NAME,
                        ProviderContract.Action.ME_LABEL, ProviderContract.Action.RESERVED_AMOUNT,
                        ProviderContract.Action.OFFERED_AMOUNT, ProviderContract.Action.TAKEN_AMOUNT,
                        ProviderContract.Action.LAST_CHANGE, ProviderContract.Action.DESCRIPTION,
                        ProviderContract.Action.ME_RELATIVE_ID, ProviderContract.Action.ME_PORTAL_ID },
                ProviderContract.Action.ENTRY_TYPE + " != " + ProviderContract.ACTION_ENTRY_TYPE_VIRTUAL, null,
                "MAX(" + ProviderContract.Action.ME_DATE + ", " + ProviderContract.Action.LAST_CHANGE
                        + " ) DESC, " + ProviderContract.Action.SYNC_STATUS + " ASC");
    }
    default:
        throw new UnsupportedOperationException("Unknown loader id: " + id);
    }
}

From source file:com.kyakujin.android.autoeco.ui.EcoFragment.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle arg) {
    switch (id) {
    case EcoQuery.LOADER_ID:
        return new CursorLoader(getActivity(),
                Uri.withAppendedPath(EcoTbl.CONTENT_URI, String.valueOf(mCurrentEcoId)), EcoQuery.PROJECTION,
                null, null, null);/*from   ww  w  . j av a 2 s.co  m*/

    default:
        break;
    }
    return null;
}

From source file:cz.maresmar.sfm.view.menu.portal.PortalMenuPagerFragment.java

@NonNull
@Override/*from w  w w .  ja  va 2s .  com*/
public Loader<Cursor> onCreateLoader(int id, @Nullable Bundle args) {
    switch (id) {
    case PORTAL_LOADER_ID:
        Uri portalsUri = Uri.withAppendedPath(mUserUri, ProviderContract.PORTAL_PATH);
        return new CursorLoader(getContext(), portalsUri, new String[] { ProviderContract.Portal._ID }, null,
                null, null);
    default:
        throw new UnsupportedOperationException("Unknown loader id: " + id);
    }
}

From source file:info.wncwaterfalls.app.FullScreenImageActivity.java

private Intent getDefaultShareIntent() {
    // Copy the image to the media store for sharing.
    Uri media_store_uri;/*w  w  w  .ja  va  2 s  .c om*/
    boolean failed = false;

    // See if image is already in media store
    String[] projection = { MediaStore.Images.Media._ID };
    String selection = MediaStore.Images.Media.TITLE + "=?";
    String[] selectionArgs = { mWaterfallName };
    Cursor c = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, selection,
            selectionArgs, null);

    if (c != null && c.getCount() > 0) {
        c.moveToFirst();
        media_store_uri = Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, c.getString(0));
    } else {
        ContentValues values = new ContentValues();
        values.put(MediaStore.Images.Media.TITLE, mWaterfallName);
        values.put(MediaStore.Images.Media.DESCRIPTION, "This is " + mWaterfallName + ".");
        values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");

        media_store_uri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);

        // Open bitmap and recompress directly to media store.
        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), mImgResourceId);
        OutputStream stream;
        try {
            stream = getContentResolver().openOutputStream(media_store_uri);
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
            stream.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            failed = true;
        } catch (IOException e) {
            e.printStackTrace();
            failed = true;
        }

        // Done copying image to media store. Recycle it.
        bitmap.recycle();
        bitmap = null;
    }

    // Safe to display image now
    populateImageView();

    // Create intent and add image to it
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("image/jpeg");

    intent.putExtra(Intent.EXTRA_SUBJECT, "Photo from WNCWaterfalls.info");
    intent.putExtra(Intent.EXTRA_TEXT, "This is " + mWaterfallName + ".");
    if (!failed) {
        intent.putExtra(Intent.EXTRA_STREAM, media_store_uri);
    } else {
        Context context = getApplicationContext();
        CharSequence text = "Oops...couldn't add image attachment :(";
        int duration = Toast.LENGTH_SHORT;
        Toast toast = Toast.makeText(context, text, duration);
        toast.show();
    }

    return intent;
}