List of usage examples for android.app Activity finish
public void finish()
From source file:org.acra.ErrorReporter.java
/** * End the application.//from ww w . jav a 2 s . c om */ private void endApplication(Thread uncaughtExceptionThread, Throwable th) { // TODO It would be better to create an explicit config attribute #letDefaultHandlerEndApplication // as the intent is clearer and would allows you to switch it off for SILENT. final boolean letDefaultHandlerEndApplication = (ACRA.getConfig().mode() == ReportingInteractionMode.SILENT || (ACRA.getConfig().mode() == ReportingInteractionMode.TOAST && ACRA.getConfig().forceCloseDialogAfterToast())); final boolean handlingUncaughtException = uncaughtExceptionThread != null; if (handlingUncaughtException && letDefaultHandlerEndApplication && (mDfltExceptionHandler != null)) { // Let the system default handler do it's job and display the force close dialog. ACRA.log.d(LOG_TAG, "Handing Exception on to default ExceptionHandler"); mDfltExceptionHandler.uncaughtException(uncaughtExceptionThread, th); } else { // If ACRA handles user notifications with a Toast or a Notification // the Force Close dialog is one more notification to the user... // We choose to close the process ourselves using the same actions. ACRA.log.e(LOG_TAG, mContext.getPackageName() + " fatal error : " + th.getMessage(), th); // Trying to solve // https://github.com/ACRA/acra/issues/42#issuecomment-12134144 // Determine the current/last Activity that was started and close // it. Activity#finish (and maybe it's parent too). final Activity lastActivity = lastActivityCreated.get(); if (lastActivity != null) { ACRA.log.i(LOG_TAG, "Finishing the last Activity prior to killing the Process"); lastActivity.finish(); ACRA.log.i(LOG_TAG, "Finished " + lastActivity.getClass()); lastActivityCreated.clear(); } android.os.Process.killProcess(android.os.Process.myPid()); System.exit(10); } }
From source file:org.eypgvnm.camera2api.CameraFragment.java
@Override public void onClick(View view) { switch (view.getId()) { case R.id.capturePicture: { takePicture();// w w w . j a va2s . co m break; } case R.id.backOrFrontCamera: { Activity activity = getActivity(); if (null != activity) { changeCamera(); } break; } case R.id.goBackCamera: { Activity activity = getActivity(); closeCamera(); activity.finish(); break; } } }
From source file:com.ultramegasoft.flavordex2.fragment.EditCatFragment.java
/** * Save the category data and close the Activity. *//*from w ww. j a va 2s.c o m*/ private void saveData() { final Activity activity = getActivity(); if (activity == null || !validateForm()) { return; } final ContentValues info = new ContentValues(); if (mTxtTitle != null) { final String title = EntryUtils.filterName(mTxtTitle.getText().toString()); info.put(Tables.Cats.NAME, title); } new DataSaver(activity, info, mExtraFields, mFlavorFields, mCatId).execute(); activity.finish(); }
From source file:org.thialfihar.android.apg.ui.EncryptMessageFragment.java
private void encryptStart(final boolean toClipboard) { // Send all information needed to service to edit key in other thread Intent intent = new Intent(getActivity(), ApgIntentService.class); intent.setAction(ApgIntentService.ACTION_ENCRYPT_SIGN); // fill values for this action Bundle data = new Bundle(); data.putInt(ApgIntentService.TARGET, ApgIntentService.TARGET_BYTES); String message = mMessage.getText().toString(); if (mEncryptInterface.isModeSymmetric()) { Log.d(Constants.TAG, "Symmetric encryption enabled!"); String passphrase = mEncryptInterface.getPassphrase(); if (passphrase.length() == 0) { passphrase = null;/* w w w.j a v a 2 s . c o m*/ } data.putString(ApgIntentService.ENCRYPT_SYMMETRIC_PASSPHRASE, passphrase); } else { data.putLong(ApgIntentService.ENCRYPT_SIGNATURE_KEY_ID, mEncryptInterface.getSignatureKey()); data.putLongArray(ApgIntentService.ENCRYPT_ENCRYPTION_KEYS_IDS, mEncryptInterface.getEncryptionKeys()); boolean signOnly = (mEncryptInterface.getEncryptionKeys() == null || mEncryptInterface.getEncryptionKeys().length == 0); if (signOnly) { message = fixBadCharactersForGmail(message); } } data.putByteArray(ApgIntentService.ENCRYPT_MESSAGE_BYTES, message.getBytes()); data.putBoolean(ApgIntentService.ENCRYPT_USE_ASCII_ARMOR, true); int compressionId = Preferences.getPreferences(getActivity()).getDefaultMessageCompression(); data.putInt(ApgIntentService.ENCRYPT_COMPRESSION_ID, compressionId); intent.putExtra(ApgIntentService.EXTRA_DATA, data); final Activity activity = getActivity(); // Message is received after encrypting is done in ApgIntentService ApgIntentServiceHandler saveHandler = new ApgIntentServiceHandler(getActivity(), getString(R.string.progress_encrypting), ProgressDialog.STYLE_HORIZONTAL) { public void handleMessage(Message message) { // handle messages by standard ApgIntentServiceHandler first super.handleMessage(message); if (message.arg1 == ApgIntentServiceHandler.MESSAGE_OKAY) { // get returned data bundle Bundle data = message.getData(); String output = new String(data.getByteArray(ApgIntentService.RESULT_BYTES)); Log.d(Constants.TAG, "output: " + output); if (mLegacyMode) { Intent result = new Intent(); result.putExtra("encryptedMessage", output); activity.setResult(activity.RESULT_OK, result); activity.finish(); return; } else if (toClipboard) { ClipboardReflection.copyToClipboard(getActivity(), output); AppMsg.makeText(getActivity(), R.string.encrypt_sign_clipboard_successful, AppMsg.STYLE_INFO).show(); } else { Intent sendIntent = new Intent(Intent.ACTION_SEND); // Type is set to text/plain so that encrypted messages can // be sent with Whatsapp, Hangouts, SMS etc... sendIntent.setType("text/plain"); sendIntent.putExtra(Intent.EXTRA_TEXT, output); startActivity(Intent.createChooser(sendIntent, getString(R.string.title_share_with))); } } } }; // Create a new Messenger for the communication back Messenger messenger = new Messenger(saveHandler); intent.putExtra(ApgIntentService.EXTRA_MESSENGER, messenger); // show progress dialog saveHandler.showProgressDialog(getActivity()); // start service with intent getActivity().startService(intent); }
From source file:com.apptentive.android.sdk.module.engagement.interaction.view.NavigateToLinkInteractionView.java
@Override public void doOnCreate(Activity activity, Bundle savedInteraction) { boolean success = false; try {/*from w ww . j a v a2 s . c o m*/ String url = interaction.getUrl(); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); switch (interaction.getTarget()) { case New: intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); break; case Self: // Nothing break; default: break; } activity.startActivity(intent); success = true; } catch (ActivityNotFoundException e) { Log.w("NavigateToLink Error: ", e); } finally { JSONObject data = new JSONObject(); try { data.put(NavigateToLinkInteraction.KEY_URL, interaction.getUrl()); data.put(NavigateToLinkInteraction.KEY_TARGET, interaction.getTarget().lowercaseName()); data.put(NavigateToLinkInteraction.EVENT_KEY_SUCCESS, success); } catch (JSONException e) { Log.e("Error creating Event data object.", e); } EngagementModule.engageInternal(activity, interaction, NavigateToLinkInteraction.EVENT_NAME_NAVIGATE, data.toString()); // Always finish this Activity. activity.finish(); } }
From source file:org.apps8os.motivator.ui.MoodHistoryActivity.java
/** * Actions for the menu items.//www . j ava 2 s . c om */ @Override public boolean onOptionsItemSelected(MenuItem item) { MoodHistoryWeekFragment weekFragment; switch (item.getItemId()) { // Search functionality for the search button case R.id.mood_history_search: // Spawn a dialog fragment so that the user can select a day. DialogFragment dialog = new DatePickerFragment(); dialog.show(getFragmentManager(), "datePicker"); return true; case R.id.mood_history_attribute_drinking: // Setting the selected attribute in landscape view. mSelectedAttribute = DayInHistory.AMOUNT_OF_DRINKS; weekFragment = mPagerAdapterWeek.getWeekFragment(mViewPager.getCurrentItem()); weekFragment.updateSelectedAttribute(DayInHistory.AMOUNT_OF_DRINKS, false); return true; case R.id.mood_history_attribute_moods: mSelectedAttribute = DayInHistory.MOODS; weekFragment = mPagerAdapterWeek.getWeekFragment(mViewPager.getCurrentItem()); weekFragment.updateSelectedAttribute(DayInHistory.MOODS, false); return true; case R.id.mood_history_change_sprint: // Spawn a dialog where the user can select the sprint depicted in this history. AlertDialog.Builder builder = new AlertDialog.Builder(this); final Sprint[] sprints = new SprintDataHandler(this).getSprints(); // Get the string representations of the sprints. String[] sprintsAsString = new String[sprints.length]; for (int i = 0; i < sprints.length; i++) { sprintsAsString[i] = sprints[i].getSprintTitle() + " " + sprints[i].getStartTimeInString(this); } builder.setTitle(getString(R.string.select_sprint)).setSingleChoiceItems(sprintsAsString, sprints.length - 1, null); final AlertDialog alertDialog = builder.create(); final Activity thisActivity = this; alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Start this activity again with the selected sprint as the passed Parcelable Sprint. // This is done so that the activity can update itself to the selected sprint. mCurrentSprint = sprints[alertDialog.getListView().getCheckedItemPosition()]; Intent intent = new Intent(thisActivity, MoodHistoryActivity.class); intent.putExtra(Sprint.CURRENT_SPRINT, mCurrentSprint); startActivity(intent); alertDialog.dismiss(); thisActivity.finish(); } }); alertDialog.show(); default: return super.onOptionsItemSelected(item); } }
From source file:org.videolan.vlc.util.Permissions.java
private static Dialog createDialogCompat(final Activity activity, boolean exit) { AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity) .setTitle(activity.getString(R.string.allow_storage_access_title)) .setMessage(activity.getString(R.string.allow_storage_access_description)) .setIcon(android.R.drawable.ic_dialog_alert).setPositiveButton( activity.getString(R.string.permission_ask_again), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { SharedPreferences settings = PreferenceManager .getDefaultSharedPreferences(activity); if (!settings.getBoolean("user_declined_storage_access", false)) requestStoragePermission(activity); else { Intent i = new Intent(); i.setAction("android.settings.APPLICATION_DETAILS_SETTINGS"); i.addCategory(Intent.CATEGORY_DEFAULT); i.setData(Uri .parse("package:" + VLCApplication.getAppContext().getPackageName())); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); try { activity.startActivity(i); } catch (Exception ex) { }/*w w w .jav a 2 s .com*/ } SharedPreferences.Editor editor = settings.edit(); editor.putBoolean("user_declined_storage_access", true); editor.apply(); } }); if (exit) { dialogBuilder.setNegativeButton(activity.getString(R.string.exit_app), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { activity.finish(); } }).setCancelable(false); } return dialogBuilder.show(); }
From source file:com.razerzone.store.sdk.engine.gamemaker.Plugin.java
public static String init(final String secretApiKey) { if (sEnableLogging) { Log.d(TAG, "init: secretApiKey=" + secretApiKey); }/* w ww .ja va 2s. com*/ final Activity activity = Plugin.getRelay().getCurrentActivity(); if (null == activity) { Log.d(TAG, "Current activity is null"); return sFalse; } else { Log.d(TAG, "Current activity is valid"); } final FrameLayout content = (FrameLayout) activity.findViewById(android.R.id.content); if (null == content) { Log.d(TAG, "Content is null"); return sFalse; } else { Runnable runnable = new Runnable() { public void run() { Log.d(TAG, "Disable screensaver"); content.setKeepScreenOn(true); Log.d(TAG, "Add inputView"); sInputView = new InputView(activity); Bundle developerInfo = null; try { developerInfo = StoreFacade.createInitBundle(secretApiKey); } catch (InvalidParameterException e) { Log.e(TAG, e.getMessage()); activity.finish(); return; } if (sEnableLogging) { Log.d(TAG, "developer_id=" + developerInfo.getString(StoreFacade.DEVELOPER_ID)); } if (sEnableLogging) { Log.d(TAG, "developer_public_key length=" + developerInfo.getByteArray(StoreFacade.DEVELOPER_PUBLIC_KEY).length); } sInitCompleteListener = new CancelIgnoringResponseListener<Bundle>() { @Override public void onSuccess(Bundle bundle) { if (sEnableLogging) { Log.d(TAG, "InitCompleteListener: onSuccess"); } JSONObject json = new JSONObject(); try { json.put("method", "onSuccessInit"); } catch (JSONException e1) { } String jsonData = json.toString(); sAsyncResults.add(jsonData); sInitialized = true; } @Override public void onFailure(int errorCode, String errorMessage, Bundle optionalData) { if (sEnableLogging) { Log.d(TAG, "InitCompleteListener: onFailure errorCode=" + errorCode + " errorMessage=" + errorMessage); } JSONObject json = new JSONObject(); try { json.put("method", "onFailureInit"); JSONObject data = new JSONObject(); data.put("errorCode", Integer.toString(errorCode)); data.put("errorMessage", errorMessage); json.put("data", data); } catch (JSONException e1) { } String jsonData = json.toString(); sAsyncResults.add(jsonData); } }; sStoreFacade = StoreFacade.getInstance(); try { sStoreFacade.init(activity, developerInfo, sInitCompleteListener); } catch (Exception e) { e.printStackTrace(); } sRequestLoginListener = new ResponseListener<Void>() { @Override public void onSuccess(Void result) { if (sEnableLogging) { Log.d(TAG, "sRequestLoginListener: onSuccess"); } JSONObject json = new JSONObject(); try { json.put("method", "onSuccessRequestLogin"); } catch (JSONException e1) { } String jsonData = json.toString(); sAsyncResults.add(jsonData); } @Override public void onFailure(int errorCode, String errorMessage, Bundle optionalData) { if (sEnableLogging) { Log.e(TAG, "sRequestLoginListener: onFailure errorCode=" + errorCode + " errorMessage=" + errorMessage); } JSONObject json = new JSONObject(); try { json.put("method", "onFailureRequestLogin"); JSONObject data = new JSONObject(); data.put("errorCode", Integer.toString(errorCode)); data.put("errorMessage", errorMessage); json.put("data", data); } catch (JSONException e1) { } String jsonData = json.toString(); sAsyncResults.add(jsonData); } @Override public void onCancel() { if (sEnableLogging) { Log.d(TAG, "sRequestLoginListener: onCancel"); } JSONObject json = new JSONObject(); try { json.put("method", "onCancelRequestLogin"); } catch (JSONException e1) { } String jsonData = json.toString(); sAsyncResults.add(jsonData); } }; sRequestGamerInfoListener = new ResponseListener<GamerInfo>() { @Override public void onSuccess(GamerInfo info) { if (null == info) { Log.e(TAG, "GamerInfo is null!"); return; } if (sEnableLogging) { Log.d(TAG, "sRequestGamerInfoListener: onSuccess uuid=" + info.getUuid() + " username=" + info.getUsername()); } JSONObject json = new JSONObject(); try { json.put("method", "onSuccessRequestGamerInfo"); JSONObject data = new JSONObject(); data.put("uuid", info.getUuid()); data.put("username", info.getUsername()); json.put("data", data); } catch (JSONException e1) { } String jsonData = json.toString(); sAsyncResults.add(jsonData); } @Override public void onFailure(int errorCode, String errorMessage, Bundle optionalData) { if (sEnableLogging) { Log.e(TAG, "sRequestGamerInfoListener: onFailure errorCode=" + errorCode + " errorMessage=" + errorMessage); } JSONObject json = new JSONObject(); try { json.put("method", "onFailureRequestGamerInfo"); JSONObject data = new JSONObject(); data.put("errorCode", Integer.toString(errorCode)); data.put("errorMessage", errorMessage); json.put("data", data); } catch (JSONException e1) { } String jsonData = json.toString(); sAsyncResults.add(jsonData); } @Override public void onCancel() { if (sEnableLogging) { Log.d(TAG, "sRequestGamerInfoListener: onCancel"); } JSONObject json = new JSONObject(); try { json.put("method", "onCancelRequestGamerInfo"); } catch (JSONException e1) { } String jsonData = json.toString(); sAsyncResults.add(jsonData); } }; sRequestProductsListener = new ResponseListener<List<Product>>() { @Override public void onSuccess(final List<Product> products) { if (null == products) { Log.e(TAG, "Products are null!"); return; } if (sEnableLogging) { Log.i(TAG, "sRequestProductsListener: onSuccess"); } JSONObject json = new JSONObject(); try { json.put("method", "onSuccessRequestProducts"); JSONArray data = new JSONArray(); int index = 0; for (Product product : products) { JSONObject item = new JSONObject(); try { item.put("currencyCode", product.getCurrencyCode()); item.put("description", product.getDescription()); item.put("identifier", product.getIdentifier()); item.put("localPrice", product.getLocalPrice()); item.put("name", product.getName()); item.put("originalPrice", product.getOriginalPrice()); item.put("percentOff", product.getPercentOff()); item.put("developerName", product.getDeveloperName()); data.put(index, item); ++index; } catch (JSONException e2) { } } json.put("data", data); } catch (JSONException e1) { } String jsonData = json.toString(); sAsyncResults.add(jsonData); } @Override public void onFailure(int errorCode, String errorMessage, Bundle optionalData) { if (sEnableLogging) { Log.e(TAG, "sRequestProductsListener: onFailure errorCode=" + errorCode + " errorMessage=" + errorMessage); } JSONObject json = new JSONObject(); try { json.put("method", "onFailureRequestProducts"); JSONObject data = new JSONObject(); data.put("errorCode", Integer.toString(errorCode)); data.put("errorMessage", errorMessage); json.put("data", data); } catch (JSONException e1) { } String jsonData = json.toString(); sAsyncResults.add(jsonData); } @Override public void onCancel() { if (sEnableLogging) { Log.i(TAG, "sRequestProductsListener: onCancel"); } JSONObject json = new JSONObject(); try { json.put("method", "onCancelRequestProducts"); } catch (JSONException e1) { } String jsonData = json.toString(); sAsyncResults.add(jsonData); } }; sRequestPurchaseListener = new ResponseListener<PurchaseResult>() { @Override public void onSuccess(PurchaseResult result) { if (null == result) { Log.e(TAG, "PurchaseResult is null!"); return; } if (sEnableLogging) { Log.i(TAG, "sRequestPurchaseListener: onSuccess"); } JSONObject json = new JSONObject(); try { json.put("method", "onSuccessRequestPurchase"); JSONObject data = new JSONObject(); data.put("identifier", result.getProductIdentifier()); data.put("ownerId", result.getOrderId()); json.put("data", data); } catch (JSONException e1) { } String jsonData = json.toString(); sAsyncResults.add(jsonData); } @Override public void onFailure(int errorCode, String errorMessage, Bundle optionalData) { if (sEnableLogging) { Log.e(TAG, "sRequestPurchaseListener: onFailure errorCode=" + errorCode + " errorMessage=" + errorMessage); } JSONObject json = new JSONObject(); try { json.put("method", "onFailureRequestPurchase"); JSONObject data = new JSONObject(); data.put("errorCode", Integer.toString(errorCode)); data.put("errorMessage", errorMessage); json.put("data", data); } catch (JSONException e1) { } String jsonData = json.toString(); sAsyncResults.add(jsonData); } @Override public void onCancel() { if (sEnableLogging) { Log.i(TAG, "sRequestPurchaseListener: onCancel"); } JSONObject json = new JSONObject(); try { json.put("method", "onCancelRequestPurchase"); } catch (JSONException e1) { } String jsonData = json.toString(); sAsyncResults.add(jsonData); } }; sRequestReceiptsListener = new ResponseListener<Collection<Receipt>>() { @Override public void onSuccess(Collection<Receipt> receipts) { if (null == receipts) { Log.e(TAG, "Receipts are null!"); return; } if (sEnableLogging) { Log.i(TAG, "requestReceipts onSuccess: received " + receipts.size() + " receipts"); } JSONObject json = new JSONObject(); try { json.put("method", "onSuccessRequestReceipts"); JSONArray data = new JSONArray(); int index = 0; for (Receipt receipt : receipts) { JSONObject item = new JSONObject(); try { item.put("identifier", receipt.getIdentifier()); item.put("purchaseDate", receipt.getPurchaseDate()); item.put("gamer", receipt.getGamer()); item.put("uuid", receipt.getUuid()); item.put("localPrice", receipt.getLocalPrice()); item.put("currency", receipt.getCurrency()); item.put("generatedDate", receipt.getGeneratedDate()); data.put(index, item); ++index; } catch (JSONException e2) { } } json.put("data", data); } catch (JSONException e1) { } String jsonData = json.toString(); sAsyncResults.add(jsonData); } @Override public void onFailure(int errorCode, String errorMessage, Bundle optionalData) { if (sEnableLogging) { Log.e(TAG, "requestReceipts onFailure: errorCode=" + errorCode + " errorMessage=" + errorMessage); } JSONObject json = new JSONObject(); try { json.put("method", "onFailureRequestReceipts"); JSONObject data = new JSONObject(); data.put("errorCode", Integer.toString(errorCode)); data.put("errorMessage", errorMessage); json.put("data", data); } catch (JSONException e1) { } String jsonData = json.toString(); sAsyncResults.add(jsonData); } @Override public void onCancel() { if (sEnableLogging) { Log.i(TAG, "requestReceipts onCancel"); } JSONObject json = new JSONObject(); try { json.put("method", "onCancelRequestReceipts"); } catch (JSONException e1) { } String jsonData = json.toString(); sAsyncResults.add(jsonData); } }; sShutdownListener = new CancelIgnoringResponseListener<Void>() { @Override public void onSuccess(Void aVoid) { if (sEnableLogging) { Log.i(TAG, "shutdown onSuccess"); } JSONObject json = new JSONObject(); try { json.put("method", "onSuccessShutdown"); } catch (JSONException e1) { } String jsonData = json.toString(); sAsyncResults.add(jsonData); } @Override public void onFailure(int i, String s, Bundle bundle) { if (sEnableLogging) { Log.i(TAG, "shutdown onFailure"); } JSONObject json = new JSONObject(); try { json.put("method", "onFailureShutdown"); } catch (JSONException e1) { } String jsonData = json.toString(); sAsyncResults.add(jsonData); } }; Controller.init(activity); } }; activity.runOnUiThread(runnable); } return sTrue; }
From source file:io.github.mkjung.ivi.util.Permissions.java
private static Dialog createDialogCompat(final Activity activity, boolean exit) { AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity) .setTitle(activity.getString(R.string.allow_storage_access_title)) .setMessage(activity.getString(R.string.allow_storage_access_description)) .setIcon(android.R.drawable.ic_dialog_alert).setPositiveButton( activity.getString(R.string.permission_ask_again), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { SharedPreferences settings = PreferenceManager .getDefaultSharedPreferences(activity); if (!settings.getBoolean("user_declined_storage_access", false)) requestStoragePermission(activity); else { Intent i = new Intent(); i.setAction("android.settings.APPLICATION_DETAILS_SETTINGS"); i.addCategory(Intent.CATEGORY_DEFAULT); i.setData(Uri .parse("package:" + VLCApplication.getAppContext().getPackageName())); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); try { activity.startActivity(i); } catch (Exception ex) { }/*from ww w . j av a 2 s. c o m*/ } SharedPreferences.Editor editor = settings.edit(); editor.putBoolean("user_declined_storage_access", true); Util.commitPreferences(editor); } }); if (exit) { dialogBuilder.setNegativeButton(activity.getString(R.string.exit_app), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { activity.finish(); } }).setCancelable(false); } return dialogBuilder.show(); }
From source file:org.videolan.vlc.util.Permissions.java
private static Dialog createDialog(final Activity activity, boolean exit) { android.app.AlertDialog.Builder dialogBuilder = new android.app.AlertDialog.Builder(activity) .setTitle(activity.getString(R.string.allow_storage_access_title)) .setMessage(activity.getString(R.string.allow_storage_access_description)) .setIcon(android.R.drawable.ic_dialog_alert).setPositiveButton( activity.getString(R.string.permission_ask_again), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { SharedPreferences settings = PreferenceManager .getDefaultSharedPreferences(activity); if (!settings.getBoolean("user_declined_storage_access", false)) requestStoragePermission(activity); else { Intent i = new Intent(); i.setAction("android.settings.APPLICATION_DETAILS_SETTINGS"); i.addCategory(Intent.CATEGORY_DEFAULT); i.setData(Uri .parse("package:" + VLCApplication.getAppContext().getPackageName())); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); try { activity.startActivity(i); } catch (Exception ex) { }// w w w. j a v a 2s . co m } SharedPreferences.Editor editor = settings.edit(); editor.putBoolean("user_declined_storage_access", true); editor.apply(); } }); if (exit) { dialogBuilder.setNegativeButton(activity.getString(R.string.exit_app), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { activity.finish(); } }).setCancelable(false); } return dialogBuilder.show(); }