本文整理汇总了Java中android.net.Uri.fromFile方法的典型用法代码示例。如果您正苦于以下问题:Java Uri.fromFile方法的具体用法?Java Uri.fromFile怎么用?Java Uri.fromFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.net.Uri
的用法示例。
在下文中一共展示了Uri.fromFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shareEvent
import android.net.Uri; //导入方法依赖的package包/类
private void shareEvent ()
{
String title = "Phoneypot: " + mEvent.getStartTime().toLocaleString();
//need to "send multiple" to get more than one attachment
final Intent emailIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
emailIntent.setType("text/plain");
emailIntent.putExtra(Intent.EXTRA_SUBJECT, title);
emailIntent.putExtra(Intent.EXTRA_TEXT, generateLog());
//has to be an ArrayList
ArrayList<Uri> uris = new ArrayList<>();
//convert from paths to Android friendly Parcelable Uri's
for (EventTrigger trigger : mEvent.getEventTriggers())
{
File fileIn = new File(trigger.getPath());
Uri u = Uri.fromFile(fileIn);
uris.add(u);
}
emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
startActivity(Intent.createChooser(emailIntent, getString(R.string.share_event_action)));
}
示例2: updateMediaStore
import android.net.Uri; //导入方法依赖的package包/类
public static void updateMediaStore(Context context, ArrayList<DocumentInfo> docs, String parentPath) {
try {
if(Utils.hasKitKat()){
ArrayList<String> paths = new ArrayList<>();
for(DocumentInfo doc : docs){
paths.add(parentPath + File.separator + doc.displayName);
}
String[] pathsArray = paths.toArray(new String[paths.size()]);
FileUtils.updateMediaStore(context, pathsArray);
}
else{
Uri contentUri = Uri.fromFile(new File(parentPath).getParentFile());
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, contentUri);
context.sendBroadcast(mediaScanIntent);
}
}
catch (Exception e){
e.printStackTrace();
}
}
示例3: ShareSingleImage
import android.net.Uri; //导入方法依赖的package包/类
/**
* 分享单张图片至所有第三方软件
*/
public static void ShareSingleImage(Context context, File file) {
Uri imageUri;
if (Build.VERSION.SDK_INT >= 24) {
imageUri = FileProvider.getUriForFile(context,"com.hzecool.common.fileProvider", file);
} else {
imageUri = Uri.fromFile(file);
}
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
shareIntent.setType("image/*");
context.startActivity(Intent.createChooser(shareIntent, "分享到"));
}
示例4: getSongsFiles
import android.net.Uri; //导入方法依赖的package包/类
void getSongsFiles(String Name){
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND_MULTIPLE);
intent.putExtra(Intent.EXTRA_SUBJECT, "All Songs from this Albums...");
intent.setType("image/jpeg"); /* This example is sharing jpeg images. */
ArrayList<Uri> files = new ArrayList<Uri>();
String path = crtPath + Name + "/";
for(int i = 0;i < allsong.size();i++){
if(allsong.get(i)[0].startsWith(path)){
File file = new File(allsong.get(i)[0]);
Uri uri = Uri.fromFile(file);
files.add(uri);
}
}
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files);
Ui.ef.startActivity(intent);
}
示例5: instantiateItem
import android.net.Uri; //导入方法依赖的package包/类
public Object instantiateItem(ViewGroup container, int position){
View v = inflater.inflate(R.layout.viewpager_image,null);
ImageView imgView = (ImageView) v.findViewById(R.id.viewPagerImage);
//이미지를 가져옴
Uri uri = Uri.fromFile(new File(cards.get(position)));
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(inflater.getContext().getContentResolver(),uri);
int nh = (int) (bitmap.getHeight() * (1024.0 / bitmap.getWidth()));
Bitmap scaled = Bitmap.createScaledBitmap(bitmap, 1024, nh, true);
imgView.setImageBitmap(scaled);
} catch (IOException e) {
e.printStackTrace();
}
container.addView(v);
return v;
}
示例6: getUriFromFile
import android.net.Uri; //导入方法依赖的package包/类
static Uri getUriFromFile(Context context, File file) {
Uri uri = null;
// LogUtils.i("Info", "::" + context.getApplicationInfo().targetSdkVersion + " INT:" + Build.VERSION.SDK_INT);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
uri = getUriFromFileForN(context, file);
} else {
uri = Uri.fromFile(file);
}
return uri;
}
示例7: getIntentByType
import android.net.Uri; //导入方法依赖的package包/类
private static Intent getIntentByType(String param, String type) {
Intent intent = new Intent("android.intent.action.VIEW");
intent.addCategory("android.intent.category.DEFAULT");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uri = Uri.fromFile(new File(param));
intent.setDataAndType(uri, type);
return intent;
}
示例8: getUriForFile
import android.net.Uri; //导入方法依赖的package包/类
/**
* File convert Uri
*
* @param context
* @param file
* @return
*/
private static Uri getUriForFile(Context context, File file) {
Uri fileUri = null;
if (Build.VERSION.SDK_INT >= 24) {
fileUri = getUriForFile24(context, file);
} else {
fileUri = Uri.fromFile(file);
}
return fileUri;
}
示例9: startPhotoZoom
import android.net.Uri; //导入方法依赖的package包/类
/**
* 裁剪图片
* @param uri
* @param context
*/
public static void startPhotoZoom(Uri uri, Context context, String fileName) {
File file = new File(context.getExternalCacheDir(), fileName);
Uri outputUri = Uri.fromFile(new File(file.getPath()));
String url = FileUtils.getPath(context, uri);
Intent intent = new Intent("com.android.camera.action.CROP");
//sdk>=24
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Uri imageUri = FileProvider.getUriForFile(context, "com.highway.study.provider", new File(url));//通过FileProvider创建一个content类型的Uri
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.putExtra("noFaceDetection", true);//去除默认的人脸识别,否则和剪裁匡重叠
intent.setDataAndType(imageUri, "image/*");
//19=<sdk<24
} else if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT && android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
intent.setDataAndType(Uri.fromFile(new File(url)), "image/*");
//sdk<19
} else {
intent.setDataAndType(uri, "image/*");
}
intent.putExtra("crop", "true");// crop=true 有这句才能出来最后的裁剪页面.
intent.putExtra("aspectX", 19);// 这两项为裁剪框的比例.
intent.putExtra("aspectY", 20);// x:y=1:2
intent.putExtra("outputX", 600);
intent.putExtra("outputY", 500);
intent.putExtra("output", outputUri);
intent.putExtra("outputFormat", "JPEG");// 返回格式
((Activity)context).startActivityForResult(intent, CROP_PHOTO);
}
示例10: getInstallAppIntent
import android.net.Uri; //导入方法依赖的package包/类
/**
* 获取安装App(支持7.0)的意图
*
* @param file 文件
* @param authority 7.0及以上安装需要传入清单文件中的{@code <provider>}的authorities属性
* <br>参看https://developer.android.com/reference/android/support/v4/content/FileProvider.html
* @return intent
*/
public static Intent getInstallAppIntent(final File file, final String authority) {
if (file == null) return null;
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri data;
String type = "application/vnd.android.package-archive";
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
data = Uri.fromFile(file);
} else {
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
data = FileProvider.getUriForFile(Utils.getContext(), authority, file);
}
intent.setDataAndType(data, type);
return intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
示例11: startCropActivity
import android.net.Uri; //导入方法依赖的package包/类
/**
* 跳转到裁剪页面
*
* @param source 需要裁剪的图片
*/
private void startCropActivity(Uri source) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.CHINA);
String imageFileName = "IMG_" + dateFormat.format(new Date());
Uri uri = Uri.fromFile(new File(getCacheDir(), imageFileName.concat(".jpeg")));
UCrop.of(source, uri)
.withAspectRatio(1, 1)
.withMaxResultSize(1024, 1024)
.withTargetActivity(VanCropActivity.class)
.start(this);
}
示例12: onCreate
import android.net.Uri; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
outputFilePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/myimage.png";
fileUri = Uri.fromFile(new File(outputFilePath));
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_crop);
cropped = false;
captureImage();
}
示例13: getChmFileIntent
import android.net.Uri; //导入方法依赖的package包/类
public static Intent getChmFileIntent(File file)
{
Intent intent = new Intent("android.intent.action.VIEW");
intent.addCategory("android.intent.category.DEFAULT");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uri = Uri.fromFile(file);
intent.setDataAndType(uri, "application/x-chm");
return intent;
}
示例14: FileToUri
import android.net.Uri; //导入方法依赖的package包/类
public static Uri FileToUri(File file) {
return Uri.fromFile(file);
}
示例15: createForExternal
import android.net.Uri; //导入方法依赖的package包/类
public Uri createForExternal(@NonNull String mimeType) throws IOException {
return Uri.fromFile(new File(getExternalDir(context),
String.valueOf(System.currentTimeMillis()) + "." + getExtensionFromMimeType(mimeType)));
}