本文整理匯總了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)));
}