【问题标题】:uriString after taking a photo in some devices在某些设备中拍照后的 uriString
【发布时间】:2018-11-02 20:09:37
【问题描述】:

当我在装有 Android 8.0 的 OnePlus 3 中拍照时,应用程序崩溃了,但在装有 Android 6.0 的 Genymotion 中却可以完美运行。

相机意图。

Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(takePicture, TAKE_IMAGE_REQUEST);

我如何设置 onActivityResult()

protected void onActivityResult(int requestCode, int resultCode, Intent data)
{       
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == TAKE_IMAGE_REQUEST) {
        Bitmap photo = (Bitmap) data.getExtras().get("data");
        Uri tempUri = getImageUri(getApplicationContext(), photo);

        String path = getRealPathFromURI(tempUri);
        try {
            Img img = crearImg(path);
            if (user.isOnline()) {
                Img.uploadImage(NoteActivity.this, img);
            }
        } catch (Exception e) {}

    }

}

我希望有人可以帮助我。

提前致谢。

【问题讨论】:

  • 拜托,你能展示你的logcat吗?谢谢。
  • 是的,没有具体的崩溃日志,我们无法准确回答您的问题。我想说根据版本号和模拟与真实设备,它可能与数据存储有关。 (可能是外部写入权限还是内部写入权限?)此外,众所周知,相机意图是跨多个设备的问题,因为每个制造商都有自己的自定义相机应用程序。

标签: android android-intent nullpointerexception camera


【解决方案1】:

也许添加对结果代码的检查可以防止崩溃,但不一定能解决问题?

if (requestCode == TAKE_IMAGE_REQUEST && && resultCode == RESULT_OK) {
   //your code here
} else {
   //log error here to figure out the problem
}

另外,我不确定你为什么在onActivityResult 中调用super。您应该只在您的 onPause()onResume()onStart() 等方法中需要它。 onActivityResult()在这些方法之前被调用,但是当你在输入int requestCode, int resultCode, Intent data中声明变量时,为什么要对父类进行super调用?

【讨论】:

    猜你喜欢
    • 2019-04-15
    • 2015-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多