将Uri从活动发送到另一个

时间:2016-08-14 20:42:41

标签: java android

我有这段代码:

活动1

 @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
        case FILE_SELECT_CODE:
            if (resultCode == RESULT_OK) {
                // Get the Uri of the selected file
                Uri fileUri = data.getData();
                Log.d("File", "File Uri: " + fileUri.toString());

                Intent intent = new Intent(getContext(),activity_file_sharing.class);
                intent.putExtra("Filepath", fileUri);
                startActivity(intent);
            }
            break;
    }
    super.onActivityResult(requestCode, resultCode, data);
}

在activity_file_sharing

 Bundle extras = getIntent().getExtras();
    if (extras != null && extras.containsKey("Filepath")) {
        FPath =  Uri.parse(getIntent().getStringExtra("Filepath").toString());

    }

FPath = Uri.parse(getIntent().getStringExtra("Filepath").toString());

我总是在上面一行得到一个空引用,我无法弄清楚问题是什么

我希望你们能帮忙

1 个答案:

答案 0 :(得分:0)

将其另存为String

Intent intent = new Intent(getContext(),activity_file_sharing.class);
                intent.putExtra("Filepath", fileUri.toString());
                startActivity(intent);