当我尝试打开文件时,应用程序崩溃了.它可以在Android Nougat下运行,但在Android Nougat上它会崩溃.当我尝试从SD卡打开文件而不是从系统分区打开文件时,它只会崩溃.一些许可问题?
示例代码:
File file = new File("/storage/emulated/0/test.txt");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "text/*");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent); // Crashes on this line
Run Code Online (Sandbox Code Playgroud)
日志:
android.os.FileUriExposedException:file:///storage/emulated/0/test.txt通过Intent.getData()暴露在app之外
编辑:
在定位Android Nougat时,file://不再允许使用URI.我们应该使用content://URI代替.但是,我的应用程序需要打开根目录中的文件.有任何想法吗?
我有一个可以制作图片并上传它们的应用程序.上传需要照片的文件路径,但我无法得到它.
这是我的代码:
public void maakfoto (View v) {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, mImageCaptureUri);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(photo);
knop.setVisibility(Button.VISIBLE);
System.out.println(mImageCaptureUri);
}
}
Run Code Online (Sandbox Code Playgroud)
请帮我看一下文件路径.
谢谢
我一直在研究相机应用程序,一切都在拍摄和保存图片.但是我希望在拍摄照片时将照片保存在实际照片中时显示我的Imageview.那可能吗?
现在我一直在尝试将imageView放在与绘制相机预览相同的布局中.
<FrameLayout
android:id="@+id/camera_preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
>
<ImageView
android:layout_width="50pt"
android:layout_height="50pt"
android:layout_gravity="center"
android:src="@android:drawable/star_big_on"
/>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
我想也许如果它是在与相机相同的视图上绘制的话那么它也会与图片一起看到该图像.
有谁知道这是可能的还是我必须采取另一种方法?如果是这样,那么如何做到这一点的其他解决方案的链接将不胜感激:)
谢谢!
编辑:我一直在关注这个相机教程http://developer.android.com/guide/topics/media/camera.html#manifest 如果有人想知道我如何保存图片等
编辑2:为了澄清,我希望你拍摄后,这个例子中的星星会在拍摄的照片中显示出来.因此,如果我拍摄一张墙的照片,我希望当你看到画廊中的照片时,就会在拍摄照片的同时在墙上展示星星!
我正在开发一个Android应用程序.它具有捕获图像应显示在屏幕上的功能,我需要获取该图像路径,以便我可以将该图像发送到服务器.
我能够在屏幕上显示图像,但无法获得绝对图像路径.
我正在走路:
content://media/external/images/media/1220
content://media/external/images/media/1221
Run Code Online (Sandbox Code Playgroud)
我怎样才能获得实际的图像路径?
这是我的代码:
mintent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
mintent.putExtra(MediaStore.EXTRA_OUTPUT,
MediaStore.Images.Media.EXTERNAL_CONTENT_URI.toString());
startActivityForResult(mintent, 1);
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if ((data != null && !data.toString().equalsIgnoreCase("Intent { }"))
|| requestCode == 1)
switch (requestCode) {
case 1:
try {
// Uri imageFileUri = data.getData();
// String path=getRealPathFromURI(this,imageFileUri);
// Bitmap bitmap = (Bitmap) data.getExtras().get("data");
String photoPath = null;
Bitmap bitmap = (Bitmap) data.getExtras().get("data");
Intent intent = new Intent(this, Media.class);
intent.putExtra("BitmapImage", bitmap);
Bundle b …Run Code Online (Sandbox Code Playgroud)