Example usage for android.content ContentResolver SCHEME_ANDROID_RESOURCE

List of usage examples for android.content ContentResolver SCHEME_ANDROID_RESOURCE

Introduction

In this page you can find the example usage for android.content ContentResolver SCHEME_ANDROID_RESOURCE.

Prototype

String SCHEME_ANDROID_RESOURCE

To view the source code for android.content ContentResolver SCHEME_ANDROID_RESOURCE.

Click Source Link

Usage

From source file:Main.java

public static Uri getDrawableUri(Context context, int resId) {
    Resources resources = context.getResources();
    return Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + resources.getResourcePackageName(resId)
            + '/' + resources.getResourceTypeName(resId) + '/' + resources.getResourceEntryName(resId));
}

From source file:Main.java

public static Uri getURIFromResrouceID(Context context, int resId) {
    Resources resources = context.getResources();
    Uri u = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + resources.getResourcePackageName(resId)
            + '/' + resources.getResourceTypeName(resId) + '/' + resources.getResourceEntryName(resId));
    return u;/*from ww  w. j  a  va 2 s .  c  o m*/
}

From source file:Main.java

/**
 * Get URI string from resourceId./*  ww w  . j a v a2 s  . c om*/
 *
 * @param context The context.
 * @param resourceId The resource id.
 * @return The URI string.
 */
public static String getUriString(final Context context, final int resourceId) {
    if (context == null) {
        throw new IllegalArgumentException("context == null");
    }
    return new Uri.Builder().scheme(ContentResolver.SCHEME_ANDROID_RESOURCE).authority(context.getPackageName())
            .appendPath(Integer.toString(resourceId)).toString();
}

From source file:Main.java

/**
 * get uri to any resource type/*from  w  w  w  .  jav a  2  s .c  o  m*/
 * @param context - context
 * @param resId - resource id
 * @throws Resources.NotFoundException if the given ID does not exist.
 * @return - Uri to resource by given id
 */
public static final Uri getUriToResource(@NonNull Context context, @AnyRes int resId)
        throws Resources.NotFoundException {
    /** Return a Resources instance for your application's package. */
    Resources res = context.getResources();
    /**
     * Creates a Uri which parses the given encoded URI string.
     * @param uriString an RFC 2396-compliant, encoded URI
     * @throws NullPointerException if uriString is null
     * @return Uri for this given uri string
     */
    Uri resUri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + res.getResourcePackageName(resId)
            + '/' + res.getResourceTypeName(resId) + '/' + res.getResourceEntryName(resId));
    /** return uri */
    return resUri;
}

From source file:Main.java

public static InputStream getInputStream(Context context, Uri uri) throws IOException {
    InputStream inputStream;/*from ww  w  . ja v a2s .  c  o m*/
    if (ContentResolver.SCHEME_ANDROID_RESOURCE.equals(uri.getScheme())
            || ContentResolver.SCHEME_ANDROID_RESOURCE.equals(uri.getScheme())
            || ContentResolver.SCHEME_FILE.equals(uri.getScheme())) {
        inputStream = context.getContentResolver().openInputStream(uri);
    } else {
        URLConnection urlConnection = new URL(uri.toString()).openConnection();
        urlConnection.setConnectTimeout(URLCONNECTION_CONNECTION_TIMEOUT_MS);
        urlConnection.setReadTimeout(URLCONNECTION_READ_TIMEOUT_MS);
        inputStream = urlConnection.getInputStream();
    }
    return new BufferedInputStream(inputStream);
}

From source file:Main.java

public static InputStream openStreamForUri(Context context, Uri uri) throws IOException {
    switch (uri.getScheme()) {
    case ContentResolver.SCHEME_CONTENT:
    case ContentResolver.SCHEME_ANDROID_RESOURCE:
        try {//  www .ja va  2s  .  co m
            return context.getContentResolver().openInputStream(uri);
        } catch (RuntimeException ignore) {
        }
    case "file":
    case "http":
    case "https":
        return new URL(uri.toString()).openStream();
    }

    throw new IOException("Unable to open " + uri.toString());
}

From source file:com.android.dialer.contactinfo.ContactPhotoLoaderTest.java

private Uri getResourceUri(int resId) {
    Context testContext = getInstrumentation().getContext();
    Resources resources = testContext.getResources();

    assertNotNull(resources.getDrawable(resId));
    return Uri.parse(
            ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + testContext.getPackageName() + '/' + resId);
}

From source file:com.android.gallery3d.data.UriImage.java

private int openOrDownloadInner(JobContext jc) {
    String scheme = mUri.getScheme();
    if (ContentResolver.SCHEME_CONTENT.equals(scheme) || ContentResolver.SCHEME_ANDROID_RESOURCE.equals(scheme)
            || ContentResolver.SCHEME_FILE.equals(scheme)) {
        try {//from  w w  w .j  a v  a2 s .c o m
            if (MIME_TYPE_JPEG.equalsIgnoreCase(mContentType)) {
                InputStream is = mApplication.getContentResolver().openInputStream(mUri);
                mRotation = Exif.getOrientation(is);
                Utils.closeSilently(is);
            }
            mFileDescriptor = mApplication.getContentResolver().openFileDescriptor(mUri, "r");
            if (jc.isCancelled())
                return STATE_INIT;
            return STATE_DOWNLOADED;
        } catch (FileNotFoundException e) {
            Log.w(TAG, "fail to open: " + mUri, e);
            return STATE_ERROR;
        }
    } else {
        try {
            URL url = new URI(mUri.toString()).toURL();
            mCacheEntry = mApplication.getDownloadCache().download(jc, url);
            if (jc.isCancelled())
                return STATE_INIT;
            if (mCacheEntry == null) {
                Log.w(TAG, "download failed " + url);
                return STATE_ERROR;
            }
            if (MIME_TYPE_JPEG.equalsIgnoreCase(mContentType)) {
                InputStream is = new FileInputStream(mCacheEntry.cacheFile);
                mRotation = Exif.getOrientation(is);
                Utils.closeSilently(is);
            }
            mFileDescriptor = ParcelFileDescriptor.open(mCacheEntry.cacheFile,
                    ParcelFileDescriptor.MODE_READ_ONLY);
            return STATE_DOWNLOADED;
        } catch (Throwable t) {
            Log.w(TAG, "download error", t);
            return STATE_ERROR;
        }
    }
}

From source file:cn.jarlen.media.sample.VideoActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_player);

    mSettings = new Settings(this);

    // handle arguments
    mVideoPath = getIntent().getStringExtra("videoPath");

    Intent intent = getIntent();/*from w ww.ja  v a  2  s. c  om*/
    String intentAction = intent.getAction();
    if (!TextUtils.isEmpty(intentAction)) {
        if (intentAction.equals(Intent.ACTION_VIEW)) {
            mVideoPath = intent.getDataString();
        } else if (intentAction.equals(Intent.ACTION_SEND)) {
            mVideoUri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                String scheme = mVideoUri.getScheme();
                if (TextUtils.isEmpty(scheme)) {
                    Log.e(TAG, "Null unknown scheme\n");
                    finish();
                    return;
                }
                if (scheme.equals(ContentResolver.SCHEME_ANDROID_RESOURCE)) {
                    mVideoPath = mVideoUri.getPath();
                } else if (scheme.equals(ContentResolver.SCHEME_CONTENT)) {
                    Log.e(TAG, "Can not resolve content below Android-ICS\n");
                    finish();
                    return;
                } else {
                    Log.e(TAG, "Unknown scheme " + scheme + "\n");
                    finish();
                    return;
                }
            }
        }
    }

    if (!TextUtils.isEmpty(mVideoPath)) {
        new RecentMediaStorage(this).saveUrlAsync(mVideoPath);
    }

    // init UI
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    ActionBar actionBar = getSupportActionBar();
    mMediaController = new AndroidMediaController(this, false);
    mMediaController.setSupportActionBar(actionBar);

    mToastTextView = (TextView) findViewById(R.id.toast_text_view);
    mHudView = (TableLayout) findViewById(R.id.hud_view);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mRightDrawer = (ViewGroup) findViewById(R.id.right_drawer);

    mDrawerLayout.setScrimColor(Color.TRANSPARENT);

    // init player
    IjkMediaPlayer.loadLibrariesOnce(null);
    IjkMediaPlayer.native_profileBegin("libijkplayer.so");

    mVideoView = (IjkVideoView) findViewById(R.id.video_view);
    mVideoView.setMediaController(mMediaController);
    mVideoView.setHudView(mHudView);
    // prefer mVideoPath
    if (mVideoPath != null)
        mVideoView.setVideoPath(mVideoPath);
    else if (mVideoUri != null)
        mVideoView.setVideoURI(mVideoUri);
    else {
        Log.e(TAG, "Null Data Source\n");
        finish();
        return;
    }
    mVideoView.start();
}

From source file:me.zuichu.ijkplayer.ui.VideoActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_player);
    mSettings = new Settings(this);
    // handle arguments
    mVideoPath = getIntent().getStringExtra("videoPath");
    Intent intent = getIntent();/* w  w  w . java2s.  c  o m*/
    String intentAction = intent.getAction();
    if (!TextUtils.isEmpty(intentAction)) {
        if (intentAction.equals(Intent.ACTION_VIEW)) {
            mVideoPath = intent.getDataString();
        } else if (intentAction.equals(Intent.ACTION_SEND)) {
            mVideoUri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                String scheme = mVideoUri.getScheme();
                if (TextUtils.isEmpty(scheme)) {
                    Log.e(TAG, "Null unknown scheme\n");
                    finish();
                    return;
                }
                if (scheme.equals(ContentResolver.SCHEME_ANDROID_RESOURCE)) {
                    mVideoPath = mVideoUri.getPath();
                } else if (scheme.equals(ContentResolver.SCHEME_CONTENT)) {
                    Log.e(TAG, "Can not resolve content below Android-ICS\n");
                    finish();
                    return;
                } else {
                    Log.e(TAG, "Unknown scheme " + scheme + "\n");
                    finish();
                    return;
                }
            }
        }
    }

    if (!TextUtils.isEmpty(mVideoPath)) {
        new RecentMediaStorage(this).saveUrlAsync(mVideoPath);
    }

    // init UI
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    ActionBar actionBar = getSupportActionBar();
    mMediaController = new AndroidMediaController(this, false);
    mMediaController.setSupportActionBar(actionBar);

    mToastTextView = (TextView) findViewById(R.id.toast_text_view);
    mHudView = (TableLayout) findViewById(R.id.hud_view);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mRightDrawer = (ViewGroup) findViewById(R.id.right_drawer);

    mDrawerLayout.setScrimColor(Color.TRANSPARENT);

    // init player
    IjkMediaPlayer.loadLibrariesOnce(null);
    IjkMediaPlayer.native_profileBegin("libijkplayer.so");

    mVideoView = (IjkVideoView) findViewById(R.id.video_view);
    mVideoView.setMediaController(mMediaController);
    mVideoView.setHudView(mHudView);
    // prefer mVideoPath
    if (mVideoPath != null)
        mVideoView.setVideoPath(mVideoPath);
    else if (mVideoUri != null)
        mVideoView.setVideoURI(mVideoUri);
    else {
        Log.e(TAG, "Null Data Source\n");
        finish();
        return;
    }
    mVideoView.start();
}