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