سلام دوستان
من وقتی با استفاده از کد های زیر آدرس یک عکس رو بدست میارم این آدرس به من نشون میده که قابل استفاده نیست یعنی سیستم غلط میگیره موقع شناساییش
File Uri: content://com.android.providers.media.documents/document/image%3A70
کد هایی که نوشتم هم اینا هست.
private static final int FILE_SELECT_CODE = 0; private void showFileChooser() { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("*/*"); intent.addCategory(Intent.CATEGORY_OPENABLE); try { startActivityForResult( Intent.createChooser(intent, "Select a File to Upload"), FILE_SELECT_CODE); } catch (android.content.ActivityNotFoundException ex) { // Potentially direct the user to the Market with a Dialog Toast.makeText(this, "Please install a File Manager.", Toast.LENGTH_SHORT).show(); } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case FILE_SELECT_CODE: if (resultCode == RESULT_OK) { // Get the Uri of the selected file Uri uri = data.getData(); Log.d("Path", "File Uri: " + uri.toString()); // Get the path String path = null; try { path = getPath(this, uri); } catch (URISyntaxException e) { e.printStackTrace(); } Log.d("Path", "File Path: " + path); // Get the file instance // File file = new File(path); // Initiate the upload addres=path; } break; } super.onActivityResult(requestCode, resultCode, data); } public static String getPath(Context context, Uri uri) throws URISyntaxException { if ("content".equalsIgnoreCase(uri.getScheme())) { String[] projection = { "_data" }; Cursor cursor = null; try { cursor = context.getContentResolver().query(uri, projection, null, null, null); int column_index = cursor.getColumnIndexOrThrow("_data"); if (cursor.moveToFirst()) { return cursor.getString(column_index); } } catch (Exception e) { // Eat it } } else if ("file".equalsIgnoreCase(uri.getScheme())) { return uri.getPath(); } return null; }
هیچ کاربری تا کنون از این پست تشکر نکرده است
با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)