List of usage examples for android.net Uri getLastPathSegment
@Nullable public abstract String getLastPathSegment();
From source file:com.odoo.support.provider.OContentProvider.java
@Override public int update(Uri uri, ContentValues values, String where, String[] whereArgs) { reInitModel();/*from w ww. j a v a 2s .c o m*/ SelectionBuilder builder = new SelectionBuilder(); final SQLiteDatabase db = model.getWritableDatabase(); final int match = matcher.match(uri); int count; switch (match) { case COLLECTION: Cursor cr = query(uri, new String[] { OColumn.ROW_ID }, where, whereArgs, null); while (cr.moveToNext()) { int id = cr.getInt(cr.getColumnIndex(OColumn.ROW_ID)); handleManyToMany(getManyToManyRecords(values), id); } cr.close(); count = builder.table(model.getTableName()).where(where, whereArgs).update(db, values); break; case SINGLE_ROW: String id = uri.getLastPathSegment(); handleManyToMany(getManyToManyRecords(values), Integer.parseInt(id)); count = builder.table(model.getTableName()).where(where, whereArgs).where(OColumn.ROW_ID + "=?", id) .where(where, whereArgs).update(db, values); break; default: throw new UnsupportedOperationException("Unknown uri: " + uri); } Context ctx = getContext(); assert ctx != null; ctx.getContentResolver().notifyChange(uri, null, false); return count; }
From source file:nl.sogeti.android.gpstracker.viewer.TrackList.java
private void displayIntent(Intent intent) { final String queryAction = intent.getAction(); final String orderby = Tracks.CREATION_TIME + " DESC"; Cursor tracksCursor = null;//from w w w. ja v a 2 s . com if (Intent.ACTION_SEARCH.equals(queryAction)) { // Got to SEARCH a query for tracks, make a list tracksCursor = doSearchWithIntent(intent); } else if (Intent.ACTION_VIEW.equals(queryAction)) { final Uri uri = intent.getData(); if ("content".equals(uri.getScheme()) && GPStracking.AUTHORITY.equals(uri.getAuthority())) { // Got to VIEW a single track, instead hand it of to the LoggerMap Intent notificationIntent = new Intent(this, LoggerMap.class); notificationIntent.setData(uri); startActivity(notificationIntent); finish(); } else if (uri.getScheme().equals("file") || uri.getScheme().equals("content")) { mImportTrackName = uri.getLastPathSegment(); // Got to VIEW a GPX filename mImportAction = new Runnable() { @Override public void run() { new GpxParser(TrackList.this, TrackList.this).execute(uri); } }; showDialog(DIALOG_IMPORT); tracksCursor = managedQuery(Tracks.CONTENT_URI, new String[] { Tracks._ID, Tracks.NAME, Tracks.CREATION_TIME }, null, null, orderby); } else { Log.e(this, "Unable to VIEW " + uri); } } else { // Got to nothing, make a list of everything tracksCursor = managedQuery(Tracks.CONTENT_URI, new String[] { Tracks._ID, Tracks.NAME, Tracks.CREATION_TIME }, null, null, orderby); } displayCursor(tracksCursor); }
From source file:net.sf.fdshare.BaseProvider.java
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { final String filePath = uri.getPath(); if (TextUtils.isEmpty(filePath)) throw new IllegalArgumentException("Empty path!"); if (projection == null) { projection = new String[] { MediaStore.MediaColumns.MIME_TYPE, OpenableColumns.DISPLAY_NAME, OpenableColumns.SIZE };/*from w w w .ja va2 s . co m*/ } final MatrixCursor result = new MatrixCursor(projection); final TimestampedMime info = guessTypeInternal(filePath); final Object[] row = new Object[projection.length]; for (int i = 0; i < projection.length; i++) { String projColumn = projection[i]; if (TextUtils.isEmpty(projColumn)) continue; switch (projColumn.toLowerCase()) { case OpenableColumns.DISPLAY_NAME: row[i] = uri.getLastPathSegment(); break; case OpenableColumns.SIZE: row[i] = info.size >= 0 ? info.size : null; break; case MediaStore.MediaColumns.MIME_TYPE: final String forcedType = uri.getQueryParameter("type"); if (!TextUtils.isEmpty(forcedType)) row[i] = "null".equals(forcedType) ? null : forcedType; else row[i] = info.mime[0]; break; case MediaStore.MediaColumns.DATA: Log.w("BaseProvider", "Relying on MediaColumns.DATA is unreliable and must be avoided!"); row[i] = uri.getPath(); break; } } result.addRow(row); return result; }
From source file:org.spontaneous.trackservice.RemoteService.java
/** * Trigged by events that start a new segment *///from www . jav a 2 s .co m private void startNewSegment() { this.mDistance = 0; this.mPreviousLocation = null; Uri newSegment = getContentResolver().insert( Uri.withAppendedPath(Tracks.CONTENT_URI, this.mTrackId + "/segments"), new ContentValues(0)); this.mSegmentId = Long.valueOf(newSegment.getLastPathSegment()).longValue(); // crashProtectState(); }
From source file:com.siviton.huanapi.data.HuanApi.java
public void downloadUpdateFile(final String path) { new Thread() { public void run() { try { File updatefile = new File(FILE_PATH); if (updatefile.exists()) { updatefile.delete(); }// ww w.j ava 2 s.com String url = path; System.out.println("===url" + url); // modified HttpClient client = new DefaultHttpClient(); HttpGet get = new HttpGet(url); HttpResponse responsedownload = client.execute(get); if (responsedownload.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { ContentValues values = new ContentValues(); values.put(Downloads.Impl.COLUMN_URI, url); values.put(Downloads.Impl.COLUMN_MIME_TYPE, "application/x-compressed"); values.put(Downloads.Impl.COLUMN_DESTINATION, Downloads.Impl.DESTINATION_SYSTEMCACHE_PARTITION); values.put(Downloads.Impl.COLUMN_FILE_NAME_HINT, FILE_PATH); values.put(Downloads.Impl.COLUMN_TITLE, "update"); values.put(Downloads.Impl.COLUMN_VISIBILITY, Downloads.Impl.VISIBILITY_VISIBLE); values.put(Downloads.Impl.COLUMN_NOTIFICATION_PACKAGE, mContext.getPackageName()); values.put(Downloads.Impl.COLUMN_NOTIFICATION_CLASS, BootBroadcast.class.getName()); Uri l = mContext.getContentResolver().insert(Downloads.Impl.CONTENT_URI, values); long id = Long.parseLong(l.getLastPathSegment()); String string = String.valueOf(id); mHuanLoginListen.StateChange(STATE_DOWNLOAD, STATE_DOWNLOAD_ISOK, string, null, null, null); System.out.println("===url" + string); // modified } else { System.out.println( "==========pengbhuan====" + responsedownload.getStatusLine().getStatusCode()); mHuanLoginListen.StateChange(STATE_DOWNLOAD, STATE_DOWNLOAD_NETCODE_ISNO200, "STATE_DOWNLOAD_NETCODE_ISNO200", null, null, null); } } catch (Exception e) { mHuanLoginListen.StateChange(STATE_DOWNLOAD, STATE_DOWNLOAD_NETCODE_EXCEPTION, e.toString(), null, null, null); } }; }.start(); }
From source file:Main.java
@TargetApi(19) public static String getImageAbsolutePath(Context context, Uri imageUri) { if (context == null || imageUri == null) return null; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT && DocumentsContract.isDocumentUri(context, imageUri)) { if (isExternalStorageDocument(imageUri)) { String docId = DocumentsContract.getDocumentId(imageUri); String[] split = docId.split(":"); String type = split[0]; if ("primary".equalsIgnoreCase(type)) { return Environment.getExternalStorageDirectory() + "/" + split[1]; }/*from ww w. ja v a2s . c om*/ } else if (isDownloadsDocument(imageUri)) { String id = DocumentsContract.getDocumentId(imageUri); Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id)); return getDataColumn(context, contentUri, null, null); } else if (isMediaDocument(imageUri)) { String docId = DocumentsContract.getDocumentId(imageUri); String[] split = docId.split(":"); String type = split[0]; Uri contentUri = null; if ("image".equals(type)) { contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; } else if ("video".equals(type)) { contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; } else if ("audio".equals(type)) { contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; } String selection = MediaStore.Images.Media._ID + "=?"; String[] selectionArgs = new String[] { split[1] }; return getDataColumn(context, contentUri, selection, selectionArgs); } } // MediaStore (and general) else if ("content".equalsIgnoreCase(imageUri.getScheme())) { // Return the remote address if (isGooglePhotosUri(imageUri)) return imageUri.getLastPathSegment(); return getDataColumn(context, imageUri, null, null); } // File else if ("file".equalsIgnoreCase(imageUri.getScheme())) { return imageUri.getPath(); } return null; }
From source file:Main.java
@TargetApi(19) public static String getImageAbsolutePath(Activity context, Uri imageUri) { if (context == null || imageUri == null) return null; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT && DocumentsContract.isDocumentUri(context, imageUri)) { if (isExternalStorageDocument(imageUri)) { String docId = DocumentsContract.getDocumentId(imageUri); String[] split = docId.split(":"); String type = split[0]; if ("primary".equalsIgnoreCase(type)) { return Environment.getExternalStorageDirectory() + "/" + split[1]; }/*from w ww. j ava 2s.c o m*/ } else if (isDownloadsDocument(imageUri)) { String id = DocumentsContract.getDocumentId(imageUri); Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id)); return getDataColumn(context, contentUri, null, null); } else if (isMediaDocument(imageUri)) { String docId = DocumentsContract.getDocumentId(imageUri); String[] split = docId.split(":"); String type = split[0]; Uri contentUri = null; if ("image".equals(type)) { contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; } else if ("video".equals(type)) { contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; } else if ("audio".equals(type)) { contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; } String selection = MediaStore.Images.Media._ID + "=?"; String[] selectionArgs = new String[] { split[1] }; return getDataColumn(context, contentUri, selection, selectionArgs); } } // MediaStore (and general) else if ("content".equalsIgnoreCase(imageUri.getScheme())) { // Return the remote address if (isGooglePhotosUri(imageUri)) return imageUri.getLastPathSegment(); return getDataColumn(context, imageUri, null, null); } // File else if ("file".equalsIgnoreCase(imageUri.getScheme())) { return imageUri.getPath(); } return null; }
From source file:com.android.music.ArtistAlbumBrowserFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent intent) { switch (requestCode) { case SCAN_DONE: if (resultCode == getActivity().RESULT_CANCELED) { getActivity().finish();// w w w .ja va 2 s . com } else { getArtistCursor(mAdapter.getQueryHandler(), null); } break; case NEW_PLAYLIST: if (resultCode == getActivity().RESULT_OK) { Uri uri = intent.getData(); if (uri != null) { long[] list = null; if (mCurrentArtistId != null) { list = MusicUtils.getSongListForArtist(getActivity(), Long.parseLong(mCurrentArtistId)); } else if (mCurrentAlbumId != null) { list = MusicUtils.getSongListForAlbum(getActivity(), Long.parseLong(mCurrentAlbumId)); } MusicUtils.addToPlaylist(getActivity(), list, Long.parseLong(uri.getLastPathSegment())); } } break; } }
From source file:com.gelakinetic.mtgfam.activities.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /* http://stackoverflow.com/questions/13179620/force-overflow-menu-in-actionbarsherlock/13180285 * //w ww . j a v a 2 s . com * Open ActionBarSherlock/src/com/actionbarsherlock/internal/view/menu/ActionMenuPresenter.java, go to method reserveOverflow * Replace the original with: * public static boolean reserveOverflow(Context context) { return true; } */ if (DEVICE_VERSION >= DEVICE_HONEYCOMB) { try { ViewConfiguration config = ViewConfiguration.get(this); Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey"); if (menuKeyField != null) { menuKeyField.setAccessible(true); menuKeyField.setBoolean(config, false); } } catch (Exception ex) { // Ignore } } mFragmentManager = getSupportFragmentManager(); try { pInfo = getPackageManager().getPackageInfo(getPackageName(), 0); } catch (NameNotFoundException e) { pInfo = null; } if (prefAdapter == null) { prefAdapter = new PreferencesAdapter(this); } int lastVersion = prefAdapter.getLastVersion(); if (pInfo.versionCode != lastVersion) { // Clear the robospice cache on upgrade. This way, no cached values w/o foil prices will exist try { spiceManager.removeAllDataFromCache(); } catch (NullPointerException e) { // eat it. tasty } showDialogFragment(CHANGELOGDIALOG); prefAdapter.setLastVersion(pInfo.versionCode); bounceMenu = lastVersion <= 15; //Only bounce if the last version is 1.8.1 or lower (or a fresh install) } File mtr = new File(getFilesDir(), JudgesCornerFragment.MTR_LOCAL_FILE); File ipg = new File(getFilesDir(), JudgesCornerFragment.IPG_LOCAL_FILE); if (!mtr.exists()) { try { InputStream in = getResources().openRawResource(R.raw.mtr); FileOutputStream fos = new FileOutputStream(mtr); IOUtils.copy(in, fos); } catch (FileNotFoundException e) { Log.w("MainActivity", "MTR file could not be copied: " + e.getMessage()); } catch (IOException e) { Log.w("MainActivity", "MTR file could not be copied: " + e.getMessage()); } } if (!ipg.exists()) { try { InputStream in = getResources().openRawResource(R.raw.ipg); FileOutputStream fos = new FileOutputStream(ipg); IOUtils.copy(in, fos); } catch (FileNotFoundException e) { Log.w("MainActivity", "IPG file could not be copied: " + e.getMessage()); } catch (IOException e) { Log.w("MainActivity", "IPG file could not be copied: " + e.getMessage()); } } ActionBar actionBar = getSupportActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); actionBar.setDisplayShowTitleEnabled(false); actionBar.setIcon(R.drawable.sliding_menu_icon); SlidingMenu slidingMenu = getSlidingMenu(); slidingMenu.setBehindWidthRes(R.dimen.sliding_menu_width); slidingMenu.setBehindScrollScale(0.0f); slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN); slidingMenu.setShadowWidthRes(R.dimen.shadow_width); slidingMenu.setShadowDrawable(R.drawable.sliding_menu_shadow); setSlidingActionBarEnabled(false); setBehindContentView(R.layout.fragment_menu); me = this; boolean autoupdate = prefAdapter.getAutoUpdate(); if (autoupdate) { // Only update the banning list if it hasn't been updated recently long curTime = new Date().getTime(); int updatefrequency = Integer.valueOf(prefAdapter.getUpdateFrequency()); int lastLegalityUpdate = prefAdapter.getLastLegalityUpdate(); // days to ms if (((curTime / 1000) - lastLegalityUpdate) > (updatefrequency * 24 * 60 * 60)) { startService(new Intent(this, DbUpdaterService.class)); } } timerHandler = new Handler(); registerReceiver(endTimeReceiver, new IntentFilter(RoundTimerFragment.RESULT_FILTER)); registerReceiver(startTimeReceiver, new IntentFilter(RoundTimerService.START_FILTER)); registerReceiver(cancelTimeReceiver, new IntentFilter(RoundTimerService.CANCEL_FILTER)); updatingDisplay = false; timeShowing = false; getSlidingMenu().setOnOpenedListener(new OnOpenedListener() { @Override public void onOpened() { // Close the keyboard if the slidingMenu is opened hideKeyboard(); } }); setContentView(R.layout.fragment_activity); getSupportFragmentManager().beginTransaction().replace(R.id.frag_menu, new MenuFragment()).commit(); showOnePane(); if (findViewById(R.id.middle_container) != null) { // The detail container view will be present only in the // large-screen layouts (res/values-large and // res/values-sw600dp). If this view is present, then the // activity should be in two-pane mode. mIsATablet = true; if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { mThreePane = true; } else { mThreePane = false; } } else { mThreePane = false; mIsATablet = false; if (findViewById(R.id.middle_container) != null) { findViewById(R.id.middle_container).setVisibility(View.GONE); findViewById(R.id.right_container).setVisibility(View.GONE); } } Intent intent = getIntent(); if (savedInstanceState == null) { try { if (intent.getAction().equals(Intent.ACTION_VIEW)) { //apparently this can NPE on 4.3. because why not. if we catch it, launch the default frag // handles a click on a search suggestion; launches activity to show word Uri u = intent.getData(); long id = Long.parseLong(u.getLastPathSegment()); // add a fragment Bundle args = new Bundle(); args.putBoolean("isSingle", true); args.putLong("id", id); CardViewFragment rlFrag = new CardViewFragment(); rlFrag.setArguments(args); attachSingleFragment(rlFrag, "left_frag", false, false); showOnePane(); hideKeyboard(); } else if (intent.getAction().equals(Intent.ACTION_SEARCH)) { boolean consolidate = prefAdapter.getConsolidateSearch(); String query = intent.getStringExtra(SearchManager.QUERY); SearchCriteria sc = new SearchCriteria(); sc.Name = query; sc.Set_Logic = (consolidate ? CardDbAdapter.FIRSTPRINTING : CardDbAdapter.ALLPRINTINGS); // add a fragment Bundle args = new Bundle(); args.putBoolean(SearchViewFragment.RANDOM, false); args.putSerializable(SearchViewFragment.CRITERIA, sc); if (mIsATablet) { SearchViewFragment svFrag = new SearchViewFragment(); svFrag.setArguments(args); attachSingleFragment(svFrag, "left_frag", false, false); } else { ResultListFragment rlFrag = new ResultListFragment(); rlFrag.setArguments(args); attachSingleFragment(rlFrag, "left_frag", false, false); } hideKeyboard(); } else if (intent.getAction().equals(ACTION_FULL_SEARCH)) { attachSingleFragment(new SearchViewFragment(), "left_frag", false, false); showOnePane(); } else if (intent.getAction().equals(ACTION_WIDGET_SEARCH)) { attachSingleFragment(new SearchWidgetFragment(), "left_frag", false, false); showOnePane(); } else if (intent.getAction().equals(ACTION_ROUND_TIMER)) { attachSingleFragment(new RoundTimerFragment(), "left_frag", false, false); showOnePane(); } else { launchDefaultFragment(); } } catch (NullPointerException e) { launchDefaultFragment(); } } }
From source file:com.openerp.base.ir.Attachment.java
private String[] getFileName(Uri uri) { String[] file_info = null;/*from ww w . j a v a2 s . co m*/ String filename = ""; String file_type = ""; if (uri.getScheme().toString().compareTo("content") == 0) { Cursor cursor = mContext.getContentResolver().query(uri, null, null, null, null); if (cursor.moveToFirst()) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); filename = cursor.getString(column_index); File fl = new File(filename); filename = fl.getName(); } file_type = mContext.getContentResolver().getType(uri); } else if (uri.getScheme().compareTo("file") == 0) { filename = uri.getLastPathSegment().toString(); file_type = "file"; } else { filename = filename + "_" + uri.getLastPathSegment(); file_type = "file"; } file_info = new String[] { filename, file_type }; return file_info; }