@Override public void onRequestPermissionsResult( int requestCode, String[] permissions, int[] grantResults) { switch (requestCode) { case STORAGE_PERMISSION_REQUEST_CODE: if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED && selectDownloadFolderFragment != null) selectDownloadFolderFragment.show(getFragmentManager(), SELECT_FOLDER_DIALOG_TAG); else { showToast(getString(R.string.file_select_access_denied)); onCancel(null); } } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState == null) { selectDownloadFolderFragment = new SelectDownloadFolderFragment(); selectDownloadFolderFragment.setStyle(DialogFragment.STYLE_NORMAL, R.style.AppDialog); // Make sure we have the permission needed if (!Podcatcher.canWriteExternalStorage()) requestPermissions(new String[] {WRITE_EXTERNAL_STORAGE}, STORAGE_PERMISSION_REQUEST_CODE); else selectDownloadFolderFragment.show(getFragmentManager(), SELECT_FOLDER_DIALOG_TAG); } else this.selectDownloadFolderFragment = (SelectDownloadFolderFragment) getFragmentManager().findFragmentByTag(SELECT_FOLDER_DIALOG_TAG); }