Android ParcelFileDescriptor - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android ParcelFileDescriptor class.

This code example shows how to use the following methods:open, exists
  } 
 
  @Override 
  public ParcelFileDescriptor openFile(Uri uri, String mode)
                                                            throws FileNotFoundException { 
    File f=new File(getContext().getFilesDir(), uri.getPath());
 
    if (f.exists()) {
      return(ParcelFileDescriptor.open(f,
                                       ParcelFileDescriptor.MODE_READ_ONLY));
    } 
 
    throw new FileNotFoundException(uri.getPath());
  } 
 
  @Override 
  public Cursor query(Uri url, String[] projection, String selection,
                      String[] selectionArgs, String sort) {
    throw new RuntimeException("Operation not supported");
  } 
8
CodeRank
This code example shows how to use the following methods:open, exists
  } 
 
  @Override 
  public ParcelFileDescriptor openFile(Uri uri, String mode)
                                                            throws FileNotFoundException { 
    File f=new File(getContext().getFilesDir(), uri.getPath());
 
    if (f.exists()) {
      return(ParcelFileDescriptor.open(f,
                                       ParcelFileDescriptor.MODE_READ_ONLY));
    } 
 
    throw new FileNotFoundException(uri.getPath());
  } 
 
  @Override 
  public Cursor query(Uri url, String[] projection, String selection,
                      String[] selectionArgs, String sort) {
    throw new RuntimeException("Operation not supported");
  } 
8
CodeRank
This code example shows how to use the following methods:open, createNewFile, exists
		Log.d(tag, "File name = " + fileName);
		 
//		String pass = uri.getQueryParameter(Sign.ContentUrl.PARAM_PASSWORD); 
//		Log.d(tag, "Password = " + pass); 
		 
		File path = new File(root, fileName);
 
		int imode = 0;
		if (mode.contains("w")) {
			imode |= ParcelFileDescriptor.MODE_WRITE_ONLY;
			root.mkdirs();
			if (!path.exists()) {
				try { 
					path.createNewFile();
				} catch (IOException e) {
					Log.w(tag, e);
					throw new FileNotFoundException("Cannot create file");
				} 
			} 
		} 

7
CodeRank
This code example shows how to use the following methods:getFileDescriptor
 
    private void openAccessory(UsbAccessory accessory) {
        Log.d(TAG, "openAccessory: " + accessory);
        mFileDescriptor = mUsbManager.openAccessory(accessory);
        if (mFileDescriptor != null) {
            FileDescriptor fd = mFileDescriptor.getFileDescriptor();
            mInputStream = new FileInputStream(fd);
            mOutputStream = new FileOutputStream(fd);
            Thread thread = new Thread(null, this, "AccessoryChat");
            thread.start();
            Log.d(TAG, "openAccessory succeeded");
        } else { 
            Log.d(TAG, "openAccessory fail");
        } 
    } 
 
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        if (actionId == EditorInfo.IME_ACTION_DONE && mOutputStream != null) {
            try { 
                mOutputStream.write(v.getText().toString().getBytes());
7
CodeRank
This code example shows how to use the following methods:open
        return 0; 
    } 
 
    public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
        String path = fileContextAdapter.getAbsolutePathForAsset(uri.getPath());
        File f = new File(path + "nr");
        return ParcelFileDescriptor.open(f, ParcelFileDescriptor.MODE_READ_ONLY);
    } 
 
} 
6
CodeRank
This code example shows how to use the following methods:open, createNewFile, exists
            return null; 
        } 
 
        File root = new File(Environment.getExternalStorageDirectory(), "/Android/data/com.frostwire.android/cache");
        root.mkdirs();
        File path = new File(root, uri.getEncodedPath().replace("/", "_"));
 
        int imode = 0;
        if (mode.contains("w")) {
            imode |= ParcelFileDescriptor.MODE_WRITE_ONLY;
            if (!path.exists()) {
                try { 
                    path.createNewFile();
                } catch (IOException e) {
                    e.printStackTrace();
                } 
            } 
        } 
        if (mode.contains("r")) {
            imode |= ParcelFileDescriptor.MODE_READ_ONLY;

6
CodeRank
This code example shows how to use the following methods:getFileDescriptor
        try { 
            input = mContentResolver.openFileDescriptor(mUri, "r");
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inJustDecodeBounds = true;
            BitmapManager.instance().decodeFileDescriptor( 
                    input.getFileDescriptor(), options);
            mWidth = options.outWidth;
            mHeight = options.outHeight;
        } catch (FileNotFoundException ex) {
            mWidth = 0;
            mHeight = 0;
        } finally { 
            Util.closeSilently(input);
        } 
    } 
 
    public int getWidth() { 
        if (mWidth == UNKNOWN_LENGTH) setupDimension();
        return mWidth;
    } 
6
CodeRank
This code example shows how to use the following methods:getStatSize
     * 
     * @param pfd The input file to compare the size of 
     * @param size The expected size of the file 
     */ 
    protected void verifyFileSize(ParcelFileDescriptor pfd, long size) {
        assertEquals(pfd.getStatSize(), size);
    } 
 
    /** 
     * Helper to create and register a new MultipleDownloadCompletedReciever 
     * 
     * This is used to track many simultaneous downloads by keeping count of all the downloads 
     * that have completed. 
     * 
     * @return A new receiver that records and can be queried on how many downloads have completed. 
     */ 
    protected MultipleDownloadsCompletedReceiver registerNewMultipleDownloadsReceiver() { 
        MultipleDownloadsCompletedReceiver receiver = new MultipleDownloadsCompletedReceiver();
        mContext.registerReceiver(receiver, new IntentFilter(
                DownloadManager.ACTION_DOWNLOAD_COMPLETE));
6
CodeRank
This code example shows how to use the following methods:open, exists
 
    public ParcelFileDescriptor getWallpaper(IWallpaperServiceCallback cb) {
        try { 
            mCallbacks.register(cb);
            File f = WALLPAPER_FILE;
            if (!f.exists()) {
                return null; 
            } 
            return ParcelFileDescriptor.open(f, MODE_READ_ONLY);
        } catch (FileNotFoundException e) {
             
            /* Shouldn't happen as we check to see if the file exists */ 
            if (Config.LOGD) Log.d(TAG, "Error getting wallpaper", e);
        } 
        return null; 
    } 
 
    public ParcelFileDescriptor setWallpaper() {
        checkPermission(android.Manifest.permission.SET_WALLPAPER);
        try { 
6
CodeRank
This code example shows how to use the following methods:open
			throws FileNotFoundException { 
		if (uri.toString().startsWith(FILE_PROVIDER_PREFIX)) {
			int m = ParcelFileDescriptor.MODE_READ_ONLY;
			if (mode.equalsIgnoreCase("rw"))
				m = ParcelFileDescriptor.MODE_READ_WRITE;
			File f = new File(uri.getPath());
			ParcelFileDescriptor pfd = ParcelFileDescriptor.open(f, m);
			return pfd;
		} else { 
			throw new FileNotFoundException	("Unsupported uri: " + uri.toString());
		} 
	} 
 
	@Override 
	public int update(Uri uri, ContentValues contentvalues, String s, String[] as) {
		// not supported 
		return 0; 
	} 
 
} 
6
CodeRank

Related Android ParcelFileDescriptor Questions & Answers:

See Code Examples for Android ParcelFileDescriptor Methods: