2

如何使用意图获取文件路径。我正在使用此代码来选择文件

 Intent intent = new Intent(Intent.ACTION_GET_CONTENT); 
 intent.setType("*/*"); 
// intent.setData(uri);
   intent.addCategory(Intent.CATEGORY_OPENABLE);
   try {
        startActivityForResult(
         Intent.createChooser(intent, "Select a File to Upload"),PICKFILE_RESULT_CODE);
       } catch (android.content.ActivityNotFoundException ex) 
       {// Potentially direct the user to the Market with a Dialog
   Toast.makeText(getApplicationContext(), "Please install a File Manager.", Toast.LENGTH_LONG).show();
                            }

现在我想获取实际的文件路径

@Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      if (requestCode == PICKFILE_RESULT_CODE && resultCode == RESULT_OK
                        && data != null) {
    Uri selectedFile = data.getData();


                String[] filePathColum = {  };

                Cursor cursor = getContentResolver().query(selectedFile,
                        filePathColum, null, null, null);
                cursor.moveToFirst();

                int columnIndex = cursor.getColumnIndex(filePathColum[0]);

                String FilePath = cursor.getString(columnIndex);

但是当我尝试获取文件路径时,它崩溃了我如何获取文件路径

4

0 回答 0