我正在构建一个简单的相机应用程序在Android中显示它在imageView
。我可以得到非常模糊的缩略图。所以我有一个制作的文件,然后它给了我的文件的位置。当我检查它时,它是0 kb,这是很好理解。 我的任务是捕获图像并保存在mCurrentPhotoPath
,我应该能够在我imageView
在startActivityForResult()
如何在位置获取图像并在Android应用程序中检索imageView?
显示它不过应用崩溃连连Caling在此之前之前。 我知道的东西是越野车在这条线
Uri photoURI = FileProvider.getUriForFile(MainActivity.this,"com.infolabs.photu", photoFile);
。我已经改变了Uri photoURI = FileProvider.getUriForFile(this, "com.example.android.fileprovider",photoFile);
到com.infolabs.photu
。但我不能让什么是错的吧。
请看看我的代码,我有位置URL的位置,但它不会显示或工作的形象是0KB
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b = (Button) findViewById(R.id.captureimage);
imageView = (ImageView) findViewById(R.id.imageView);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null)
{
// Create the File where the photo should go
File photoFile = null;
try
{
photoFile = createImageFile();
Toast.makeText(MainActivity.this,mCurrentPhotoPath,Toast.LENGTH_LONG).show();
}
catch (IOException ex)
{
Toast.makeText(MainActivity.this,"the file is not created ",Toast.LENGTH_SHORT).show();
}
if (photoFile != null)
{
//this Uri does not working properly
Uri photoURI = FileProvider.getUriForFile(MainActivity.this,"com.infolabs.photu", photoFile);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
}
}
}
});
}
错误日志: - 致命异常:主要 过程:infolabs PID:21415 java.lang.NullPointerException:试图调用虚方法android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager,java.lang.String) '在android.support.v4.content.FileProvider.parsePathStrategy上的空对象引用 (FileProvider.java:58 3) at android.support.v4.content.FileProvider.getPathStrategy(FileProvider.java:557) at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:399) at infolabs.photu.MainActivity $ 1 .onClick(MainActivity.java:71) at android.view.View.performClick(View.java:5269) at android.view.View $ PerformClick.run(View.java:21556) at android.os.Handler .handleCallback(Handler.java:815) at android.os.Handler.dispatchMessage(Handler.java:104) at android.os.Looper.loop(Looper.java:207) at android.app.ActivityThread.main (ActivityThread.java:5776) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:789) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:679) 04-17 16:56:15.085 21415-21425/infolabs.photu I /系统:FinalizerDaemon:最终确定的对象= 65
如果它崩溃,那么也发布你的崩溃日志。 –
您可以在“Uri photoURI = FileProvider.getUriForFile(MainActivity.this,”com.infolabs.photu“,photoFile)中添加调试点;”并手动打开文件并检查文件的大小。 – Sarker
是的,我没有显示0kb –