【问题标题】:Intent data is null意图数据为空
【发布时间】:2016-07-22 02:39:44
【问题描述】:

我在从相机获取照片时遇到问题

Bundle extras = new Bundle()
extras.putString("photo",photo.getPath());
extras.putParcelable(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
cameraIntent.putExtras(extras);
startActivityForResult(cameraIntent, Constants.CAMERA_REQUEST);

我正在尝试获取数据:

case Constants.CAMERA_REQUEST: {
    if (resultCode != RESULT_OK)
        return;
    if (data != null) {
        Bundle extras = data.getExtras(); //data always null
        SetPhotoToView(extras.getString("photo"));
    }
    break;

【问题讨论】:

标签: java android android-camera android-camera-intent


【解决方案1】:

尝试使用它来获取意图值

getIntent().getStringExtra("photo") ;

    Bundle b = new Bundle();
    b = getIntent().getExtras();
    String name = b.getString("name");

【讨论】:

  • 试试这个方法来获取bundle Bundle b = new Bundle(); b = getIntent().getExtras();字符串名称 = b.getString("keyname");
  • 那么它们是作为捆绑发送数据的问题
  • 图库数据发送正常,仅相机有问题
  • 在onactivity结果中记录数据。然后你可以找到返回的数据
【解决方案2】:
if (data != null) { // Before this check 

在检查数据为 Null 或未从 Intent 获取数据之前

String data = getIntent().getExtras().getString("photo");

然后检查数据是否为 ​​Null

if(data != null){
    //DEAL WITH YOUR DATA
}

【讨论】:

    猜你喜欢
    • 2018-10-20
    • 2019-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多