下面列出了android.content.ContentResolver#SCHEME_ANDROID_RESOURCE 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Create a bundle from the list of URIs
* @param uriList list of URIs to add
* @return newly created bundle
*/
private Bundle createBundle(ArrayList<Parcelable> uriList) throws IOException {
Bundle bundle = new Bundle();
for (Parcelable parcelable : uriList) {
Uri uri = (Uri) parcelable;
switch (uri.getScheme()) {
case ContentResolver.SCHEME_ANDROID_RESOURCE:
case ContentResolver.SCHEME_CONTENT:
bundle.addItem(new FileItem(
getAssetFileDescriptor(uri),
getFilename(uri)
));
break;
case ContentResolver.SCHEME_FILE:
File file = new File(uri.getPath());
if (file.isDirectory()) {
traverseDirectory(file, bundle);
} else {
bundle.addItem(new FileItem(file));
}
break;
}
}
return bundle;
}
/**
* get uri to drawable or any other resource type if u wish
* @param context - context
* @param drawableId - drawable res id
* @return - uri
*/
public static String getUriToDrawable(@NonNull Context context, @AnyRes int drawableId) {
String imageUri = ContentResolver.SCHEME_ANDROID_RESOURCE +
"://" + context.getResources().getResourcePackageName(drawableId)
+ '/' + context.getResources().getResourceTypeName(drawableId)
+ '/' + context.getResources().getResourceEntryName(drawableId);
return imageUri;
}
@Override
public void startDemo() {
Intent intent = new Intent(mContext, FatBeaconBroadcastService.class);
intent.putExtra(FatBeaconBroadcastService.TITLE_KEY, "Hello World");
String uriString = ContentResolver.SCHEME_ANDROID_RESOURCE + "://" +
mContext.getPackageName() + "/" + R.raw.fatbeacon_default_webpage;
intent.putExtra(FatBeaconBroadcastService.URI_KEY, uriString);
mContext.startService(intent);
mIsDemoStarted = true;
}
@Override
public void startDemo() {
Intent intent = new Intent(mContext, FileBroadcastService.class);
String uriString = ContentResolver.SCHEME_ANDROID_RESOURCE + "://" +
mContext.getPackageName() + "/" + R.raw.wifi_direct_default_webpage;
intent.putExtra(FileBroadcastService.FILE_KEY, uriString);
intent.putExtra(FileBroadcastService.MIME_TYPE_KEY, "text/html");
intent.putExtra(FileBroadcastService.TITLE_KEY, "Hello World");
mContext.startService(intent);
mIsDemoStarted = true;
}
public static String getResourceURI(int id) {
return ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + xdrip.getAppContext().getPackageName() + "/" + id;
}
public static String getResourceURI(int id) {
return ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + xdrip.getAppContext().getPackageName() + "/" + id;
}
public static String getResourceURI(int id) {
return ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + xdrip.getAppContext().getPackageName() + "/" + id;
}
public static String getResourceURI(int id) {
return ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + xdrip.getAppContext().getPackageName() + "/" + id;
}
private static String getAlbumArtUri(String albumArtResName) {
return ContentResolver.SCHEME_ANDROID_RESOURCE + "://" +
BuildConfig.APPLICATION_ID + "/drawable/" + albumArtResName;
}