List of usage examples for android.net Uri getPath
@Nullable public abstract String getPath();
From source file:com.morphoss.acal.service.connector.AcalRequestor.java
/** * Interpret the URI in the string to set protocol, host, port & path for the next request. * If the URI only matches a path part then protocol/host/port will be unchanged. This call * will only allow for path parts that are anchored to the web root. This is used internally * for following Location: redirects.// ww w. j a va 2 s.c om * * This is also used to interpret the 'path' parameter to the request calls generally. * * @param uriString */ public void interpretUriString(String uriString) { if (uriString == null) return; // Match a URL, including an ipv6 address like http://[DEAD:BEEF:CAFE:F00D::]:8008/ final Pattern uriMatcher = Pattern.compile("^(?:(https?)://)?" + // Protocol "(" + // host spec "(?:(?:[a-z0-9-]+[.]){1,7}(?:[a-z0-9-]+))" + // Hostname or IPv4 address "|(?:\\[(?:[0-9a-f]{0,4}:)+(?:[0-9a-f]{0,4})?\\])" + // IPv6 address ")" + "(?:[:]([0-9]{2,5}))?" + // Port number "(/.*)?$" // Path bit. , Pattern.CASE_INSENSITIVE | Pattern.DOTALL); final Pattern pathMatcher = Pattern.compile("^(/.*)$"); if (Constants.LOG_VERBOSE) Log.println(Constants.LOGV, TAG, "Interpreting '" + uriString + "'"); Matcher m = uriMatcher.matcher(uriString); if (m.matches()) { if (m.group(1) != null && !m.group(1).equals("")) { if (Constants.LOG_VERBOSE) Log.println(Constants.LOGV, TAG, "Found protocol '" + m.group(1) + "'"); protocol = m.group(1); if (m.group(3) == null || m.group(3).equals("")) { port = (protocol.equals(PROTOCOL_HTTP) ? 80 : 443); } } if (m.group(2) != null) { if (Constants.LOG_VERBOSE) Log.println(Constants.LOGV, TAG, "Found hostname '" + m.group(2) + "'"); setHostName(m.group(2)); } if (m.group(3) != null && !m.group(3).equals("")) { if (Constants.LOG_VERBOSE) Log.println(Constants.LOGV, TAG, "Found port '" + m.group(3) + "'"); port = Integer.parseInt(m.group(3)); if (m.group(1) != null && (port == 0 || port == 80 || port == 443)) { port = (protocol.equals(PROTOCOL_HTTP) ? 80 : 443); } } if (m.group(4) != null && !m.group(4).equals("")) { if (Constants.LOG_VERBOSE) Log.println(Constants.LOGV, TAG, "Found path '" + m.group(4) + "'"); setPath(m.group(4)); } if (!initialised) initialise(); } else { m = pathMatcher.matcher(uriString); if (m.find()) { if (Constants.LOG_VERBOSE) Log.println(Constants.LOGV, TAG, "Found relative path '" + m.group(1) + "'"); setPath(m.group(1)); } else { if (Constants.LOG_DEBUG) Log.println(Constants.LOGD, TAG, "Using Uri class to process redirect..."); Uri newLocation = Uri.parse(uriString); if (newLocation.getHost() != null) setHostName(newLocation.getHost()); setPortProtocol(newLocation.getPort(), newLocation.getScheme()); setPath(newLocation.getPath()); if (Constants.LOG_VERBOSE) Log.println(Constants.LOGV, TAG, "Found new location at '" + fullUrl() + "'"); } } }
From source file:com.buddi.client.dfu.DfuActivity.java
@Override protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) { if (resultCode != RESULT_OK) return;/* w w w . j av a2 s . c o m*/ switch (requestCode) { case SELECT_FILE_REQ: // clear previous data mFileType = mFileTypeTmp; mFilePath = null; mFileStreamUri = null; // and read new one final Uri uri = data.getData(); /* * The URI returned from application may be in 'file' or 'content' schema. * 'File' schema allows us to create a File object and read details from if directly. * Data from 'Content' schema must be read by Content Provider. To do that we are using a Loader. */ if (uri.getScheme().equals("file")) { // the direct path to the file has been returned final String path = uri.getPath(); final File file = new File(path); mFilePath = path; updateFileInfo(file.getName(), file.length(), mFileType); } else if (uri.getScheme().equals("content")) { // an Uri has been returned mFileStreamUri = uri; // if application returned Uri for streaming, let's us it. Does it works? // FIXME both Uris works with Google Drive app. Why both? What's the difference? How about other apps like DropBox? final Bundle extras = data.getExtras(); if (extras != null && extras.containsKey(Intent.EXTRA_STREAM)) mFileStreamUri = extras.getParcelable(Intent.EXTRA_STREAM); // file name and size must be obtained from Content Provider final Bundle bundle = new Bundle(); bundle.putParcelable(EXTRA_URI, uri); //getSupportLoaderManager().restartLoader(0, bundle, this); getLoaderManager().restartLoader(0, bundle, this); } break; default: break; } }
From source file:com.fabernovel.alertevoirie.ReportDetailsActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { //Log.d("AlerteVoirie_PM", "Result : " + requestCode); switch (requestCode) { case R.id.existing_incidents_add_picture: case R.id.ImageView_far: case R.id.ImageView_close: if (resultCode == RESULT_OK) { try { String finalPath; if (data != null) { Uri path = data.getData(); // OI FILE Manager String filemanagerString = path.getPath(); // MEDIA GALLERY String selectedImagePath = getPath(path); if (selectedImagePath != null) { finalPath = selectedImagePath; System.out.println("selectedImagePath is the right one for you! " + finalPath); } else { finalPath = filemanagerString; System.out.println("filemanagerstring is the right one for you!" + finalPath); }/*w w w . ja v a 2 s .c om*/ // boolean isImage = true; } else { finalPath = uriOfPicFromCamera.getPath(); } // if (data == null || getMimeType(finalPath).startsWith("image")) { InputStream in; BitmapFactory.Options opt = new BitmapFactory.Options(); // get the sample size to have a smaller image in = getContentResolver().openInputStream(Uri.fromFile(new File(finalPath))); opt.inSampleSize = getSampleSize( getContentResolver().openInputStream(Uri.fromFile(new File(finalPath)))); in.close(); // decode a sampled version of the picture in = getContentResolver().openInputStream(Uri.fromFile(new File(finalPath))); Bitmap picture = BitmapFactory.decodeStream(in, null, opt); // Bitmap picture = BitmapFactory.decodeFile(finalPath); in.close(); File f = new File(uriOfPicFromCamera.getPath()); f.delete(); // save the new image String pictureName = requestCode == R.id.ImageView_close ? CAPTURE_CLOSE : CAPTURE_FAR; FileOutputStream fos = openFileOutput(pictureName, MODE_PRIVATE); picture.compress(CompressFormat.JPEG, 80, fos); fos.close(); if (requestCode == R.id.ImageView_far || mAdditionalImageType == ADDITIONAL_IMAGE_TYPE_FAR) { loadZoom(); } else if (mAdditionalImageType == ADDITIONAL_IMAGE_TYPE_CLOSE) { File img = new File(getFilesDir() + "/" + CAPTURE_FAR); mCurrentAction = ACTION_ADD_IMAGE; timeoutHandler.postDelayed(timeout, TIMEOUT); AVService.getInstance(this).postImage(this, Utils.getUdid(this), "", Long.toString(currentIncident.id), null, img, false); } if (requestCode != R.id.existing_incidents_add_picture) { setPictureToImageView(pictureName, (ImageView) findViewById(requestCode)); } if (requestCode == R.id.ImageView_far && ((TextView) findViewById(R.id.TextView_address)).getText().length() > 0) { ((Button) findViewById(R.id.Button_validate)).setEnabled(true); } // } // FileOutputStream fos = openFileOutput("capture", MODE_WORLD_READABLE); // InputStream in = getContentResolver().openInputStream(uriOfPicFromCamera); // Utils.fromInputToOutput(in, fos); // fos.close(); // in.close(); mAdditionalImageType = 0; } catch (FileNotFoundException e) { Log.e("AlerteVoirie_PM", "", e); } catch (IOException e) { Log.e("AlerteVoirie_PM", "", e); } catch (NullPointerException e) { AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog alert; builder.setMessage("Image invalide").setCancelable(false).setPositiveButton("Ok", null); alert = builder.create(); alert.show(); } } else if (resultCode == RESULT_CANCELED) { if (uriOfPicFromCamera != null) { File tmpFile = new File(uriOfPicFromCamera.getPath()); tmpFile.delete(); uriOfPicFromCamera = null; } } break; case REQUEST_CATEGORY: if (resultCode == RESULT_OK) { setCategory(data.getLongExtra(IntentData.EXTRA_CATEGORY_ID, -1)); // TODO do this when update request ready findViewById(R.id.Button_validate).setVisibility(View.VISIBLE); } break; case REQUEST_POSITION: if (resultCode == RESULT_OK) { currentIncident.address = data.getStringExtra(IntentData.EXTRA_ADDRESS); currentIncident.longitude = data.getDoubleExtra(IntentData.EXTRA_LONGITUDE, 0); currentIncident.latitude = data.getDoubleExtra(IntentData.EXTRA_LATITUDE, 0); ((TextView) findViewById(R.id.TextView_address)).setText(currentIncident.address); if (currentIncident.address != null && currentIncident.address.length() > 0 && canvalidate) { ((Button) findViewById(R.id.Button_validate)).setEnabled(true); } findViewById(R.id.Button_validate).setVisibility(View.VISIBLE); } break; case REQUEST_COMMENT: if (resultCode == RESULT_OK) { currentIncident.description = data.getStringExtra(IntentData.EXTRA_COMMENT); ((TextView) findViewById(R.id.TextView_comment)).setText(currentIncident.description); if (currentIncident.description != null) findViewById(R.id.TextView_nocomment).setVisibility(View.GONE); // findViewById(R.id.Button_validate).setVisibility(View.VISIBLE); } break; case REQUEST_IMAGE_COMMENT: if (resultCode == RESULT_OK) { showDialog(DIALOG_PROGRESS); File img = new File(getFilesDir() + "/arrowed.jpg"); mCurrentAction = ACTION_ADD_IMAGE; timeoutHandler.postDelayed(timeout, TIMEOUT); AVService.getInstance(this).postImage(this, Utils.getUdid(this), data.getStringExtra(IntentData.EXTRA_COMMENT), Long.toString(currentIncident.id), img, null, false); } break; case REQUEST_COMMENT_BEFORE_EXIT: if (resultCode == RESULT_OK) { currentIncident.description = data.getStringExtra(IntentData.EXTRA_COMMENT); ((TextView) findViewById(R.id.TextView_comment)).setText(currentIncident.description); postNewIncident(); } break; case REQUEST_DETAILS: if (resultCode == RESULT_OK) { // startActivityForResult(data, requestCode) if (mCurrentAction == ACTION_ADD_IMAGE) { Intent i = new Intent(getApplicationContext(), AddCommentActivity.class); startActivityForResult(i, REQUEST_IMAGE_COMMENT); } else { // set new img setPictureToImageView("arrowed.jpg", (ImageView) findViewById(R.id.ImageView_far)); loadComment(REQUEST_COMMENT); } } break; default: super.onActivityResult(requestCode, resultCode, data); break; } }
From source file:org.andstatus.app.net.http.HttpConnectionApacheCommon.java
private void fillMultiPartPost(HttpPost postMethod, JSONObject formParams) throws ConnectionException { MultipartEntityBuilder builder = MultipartEntityBuilder.create(); Uri mediaUri = null; String mediaPartName = ""; Iterator<String> iterator = formParams.keys(); ContentType contentType = ContentType.create(HTTP.PLAIN_TEXT_TYPE, HTTP.UTF_8); while (iterator.hasNext()) { String name = iterator.next(); String value = formParams.optString(name); if (HttpConnection.KEY_MEDIA_PART_NAME.equals(name)) { mediaPartName = value;//from www . j a v a2s.c o m } else if (HttpConnection.KEY_MEDIA_PART_URI.equals(name)) { mediaUri = UriUtils.fromString(value); } else { // see http://stackoverflow.com/questions/19292169/multipartentitybuilder-and-charset builder.addTextBody(name, value, contentType); } } if (!TextUtils.isEmpty(mediaPartName) && !UriUtils.isEmpty(mediaUri)) { try { InputStream ins = MyContextHolder.get().context().getContentResolver().openInputStream(mediaUri); ContentType contentType2 = ContentType.create(MyContentType.uri2MimeType(mediaUri, null)); builder.addBinaryBody(mediaPartName, ins, contentType2, mediaUri.getPath()); } catch (SecurityException e) { throw new ConnectionException("mediaUri='" + mediaUri + "'", e); } catch (FileNotFoundException e) { throw new ConnectionException("mediaUri='" + mediaUri + "'", e); } } postMethod.setEntity(builder.build()); }
From source file:Main.java
/** * Get the file path from the given Uri. * * @param context The context of the calling activity. * @param uri The Uri whose file path is returned. */// ww w . jav a2 s. c o m @TargetApi(Build.VERSION_CODES.KITKAT) public static String getFilePathFromUri(final Context context, final Uri uri) { final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; // DocumentProvider if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) { // ExternalStorageProvider if (isExternalStorageDocument(uri)) { final String docId = DocumentsContract.getDocumentId(uri); final String[] split = docId.split(":"); final String type = split[0]; if ("primary".equalsIgnoreCase(type)) { return Environment.getExternalStorageDirectory() + "/" + split[1]; } } // DownloadsProvider else if (isDownloadsDocument(uri)) { final String id = DocumentsContract.getDocumentId(uri); final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id)); return getDataColumn(context, contentUri, null, null); } // MediaProvider else if (isMediaDocument(uri)) { final String docId = DocumentsContract.getDocumentId(uri); final String[] split = docId.split(":"); final 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; } final String selection = "_id=?"; final String[] selectionArgs = new String[] { split[1] }; return getDataColumn(context, contentUri, selection, selectionArgs); } } // MediaStore (and general) else if ("content".equalsIgnoreCase(uri.getScheme())) { return getDataColumn(context, uri, null, null); } // File else if ("file".equalsIgnoreCase(uri.getScheme())) { return uri.getPath(); } return null; }
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 w ww. j a v a 2 s. co 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: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 w w . ja v a 2 s. co 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.commonsware.android.tte.DocumentStorageService.java
private void load(Uri document) { try {/*from w ww . j av a2s.c om*/ boolean weHavePermission = false; boolean isContent = ContentResolver.SCHEME_CONTENT.equals(document.getScheme()); if (isContent) { int perms = Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION; getContentResolver().takePersistableUriPermission(document, perms); for (UriPermission perm : getContentResolver().getPersistedUriPermissions()) { if (perm.getUri().equals(document)) { weHavePermission = true; } } } else { weHavePermission = true; } if (weHavePermission) { try { InputStream is = getContentResolver().openInputStream(document); try { String text = slurp(is); DocumentFile docFile; if (isContent) { docFile = DocumentFile.fromSingleUri(this, document); } else { docFile = DocumentFile.fromFile(new File(document.getPath())); } EventBus.getDefault().post( new DocumentLoadedEvent(document, text, docFile.getName(), docFile.canWrite())); } finally { is.close(); } } catch (Exception e) { Log.e(getClass().getSimpleName(), "Exception loading " + document.toString(), e); EventBus.getDefault().post(new DocumentLoadErrorEvent(document, e)); } } else { Log.e(getClass().getSimpleName(), "We failed to get permissions for " + document.toString()); EventBus.getDefault().post(new DocumentPermissionFailureEvent(document)); } } catch (SecurityException e) { Log.e(getClass().getSimpleName(), "Exception getting permissions for " + document.toString(), e); EventBus.getDefault().post(new DocumentPermissionFailureEvent(document)); } }
From source file:Main.java
@TargetApi(Build.VERSION_CODES.KITKAT) public static String getImageAbsolutePath19(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 . ja v a 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) 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.freeme.filemanager.view.FileViewFragment.java
public void init() { long time1 = System.currentTimeMillis(); //Debug.startMethodTracing("file_view"); ViewStub stub = (ViewStub) mRootView.findViewById(R.id.viewContaniner); stub.setLayoutResource(R.layout.file_explorer_list); stub.inflate();//from www . j av a 2s. c o m ActivitiesManager.getInstance().registerActivity(ActivitiesManager.ACTIVITY_FILE_VIEW, mActivity); mFileCagetoryHelper = new FileCategoryHelper(mActivity); mFileViewInteractionHub = new FileViewInteractionHub(this, 1); // */ modify by droi liuhaoran for stop run /*/ Added by tyd wulianghuan 2013-12-12 mCleanUpDatabaseHelper = new CleanUpDatabaseHelper(mActivity); mDatabase = mCleanUpDatabaseHelper.openDatabase(); mFolderNameMap = new HashMap<String, String>(); //*/ // */add by droi liuhaoran for get Sd listener on 20160419 mApplication = (FileManagerApplication) mActivity.getApplication(); // */ // notifyFileChanged(); Intent intent = mActivity.getIntent(); String action = intent.getAction(); if (!TextUtils.isEmpty(action) && (action.equals(Intent.ACTION_PICK) || action.equals(Intent.ACTION_GET_CONTENT))) { mFileViewInteractionHub.setMode(Mode.Pick); boolean pickFolder = intent.getBooleanExtra(PICK_FOLDER, false); if (!pickFolder) { String[] exts = intent.getStringArrayExtra(EXT_FILTER_KEY); if (exts != null) { mFileCagetoryHelper.setCustomCategory(exts); } } else { mFileCagetoryHelper.setCustomCategory(new String[] {} /* * folder * only */); mRootView.findViewById(R.id.pick_operation_bar).setVisibility(View.VISIBLE); mRootView.findViewById(R.id.button_pick_confirm).setOnClickListener(new OnClickListener() { public void onClick(View v) { try { Intent intent = Intent.parseUri(mFileViewInteractionHub.getCurrentPath(), 0); mActivity.setResult(Activity.RESULT_OK, intent); mActivity.finish(); } catch (URISyntaxException e) { e.printStackTrace(); } } }); mRootView.findViewById(R.id.button_pick_cancel).setOnClickListener(new OnClickListener() { public void onClick(View v) { mActivity.finish(); } }); } } else { mFileViewInteractionHub.setMode(Mode.View); } mVolumeSwitch = (ImageButton) mRootView.findViewById(R.id.volume_navigator); updateVolumeSwitchState(); mGalleryNavigationBar = (RelativeLayout) mRootView.findViewById(R.id.gallery_navigation_bar); mVolumeSwitch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { int visibility = getVolumesListVisibility(); if (visibility == View.GONE) { buildVolumesList(); showVolumesList(true); } else if (visibility == View.VISIBLE) { showVolumesList(false); } } }); mFileListView = (ListView) mRootView.findViewById(R.id.file_path_list); mFileIconHelper = new FileIconHelper(mActivity); mAdapter = new FileListAdapter(mActivity, R.layout.file_browser_item, mFileNameList, mFileViewInteractionHub, mFileIconHelper); boolean baseSd = intent.getBooleanExtra(GlobalConsts.KEY_BASE_SD, !FileExplorerPreferenceActivity.isReadRoot(mActivity)); Log.i(LOG_TAG, "baseSd = " + baseSd); String rootDir = intent.getStringExtra(ROOT_DIRECTORY); if (!TextUtils.isEmpty(rootDir)) { if (baseSd && this.sdDir.startsWith(rootDir)) { rootDir = this.sdDir; } } else { rootDir = baseSd ? this.sdDir : GlobalConsts.ROOT_PATH; } String currentDir = FileExplorerPreferenceActivity.getPrimaryFolder(mActivity); Uri uri = intent.getData(); if (uri != null) { if (baseSd && this.sdDir.startsWith(uri.getPath())) { currentDir = this.sdDir; } else { currentDir = uri.getPath(); } } initVolumeState(); mBackspaceExit = (uri != null) && (TextUtils.isEmpty(action) || (!action.equals(Intent.ACTION_PICK) && !action.equals(Intent.ACTION_GET_CONTENT))); mFileListView.setAdapter(mAdapter); IntentFilter intentFilter = new IntentFilter(); // add by xueweili for get sdcard intentFilter.setPriority(1000); /* * intentFilter.addAction(Intent.ACTION_MEDIA_MOUNTED); * intentFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED); * intentFilter.addAction(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); * intentFilter.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED); * intentFilter.addAction(Intent.ACTION_MEDIA_EJECT); */ if (!mReceiverTag) { mReceiverTag = true; intentFilter.addAction(GlobalConsts.BROADCAST_REFRESH); intentFilter.addDataScheme("file"); mActivity.registerReceiver(mReceiver, intentFilter); } // */add by droi liuhaoran for get Sd listener on 20160419 mApplication.addSDCardChangeListener(this); // */ setHasOptionsMenu(true); // add by mingjun for load file mRootView.addOnLayoutChangeListener(new OnLayoutChangeListener() { @Override public void onLayoutChange(View arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8) { isLayout = arg1; } }); loadDialog = new ProgressDialog(mRootView.getContext()); }