private void requestChangeBatteryOptimizations () { if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { Intent intent = new Intent(); String packageName = getActivity().getPackageName(); PowerManager pm = (PowerManager) getActivity().getSystemService(Context.POWER_SERVICE); if (pm.isIgnoringBatteryOptimizations(packageName)) intent.setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS); else { intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); intent.setData(Uri.parse("package:" + packageName)); } getActivity().startActivity(intent); } }
@Override public void onSuccess(String authorizeUrl) { if(getActivity() == null || state == State.CANCELLED) return; Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(authorizeUrl)); intent.putExtra(Browser.EXTRA_APPLICATION_ID, getActivity().getPackageName()); intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_SINGLE_TOP); startActivity(intent); state = State.AUTHENTICATING_IN_BROWSER; }
/** * Just a helper methods in case the user blocks permission. * It goes to your application settings page for the user to enable permission again. */ public void goToSettings() { final FragmentActivity fragmentActivity = this.activityReference.get(); if (fragmentActivity != null) { fragmentActivity.startActivity(new Intent( Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.fromParts("package", fragmentActivity.getPackageName(), null))); } }
@Override public void onClick(View view) { dismiss(); Toast.makeText(mContext, "Click Permissions to enable permissions", Toast.LENGTH_LONG).show(); Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.parse("package:" + getActivity().getPackageName())); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } });
/** * Open app settings screen */ private void openAppSettings() { Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.fromParts("package", getActivity().getPackageName(), null)); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); }
@Override public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) { try { String date = getArguments().getString(ARGUMENT_DATE); Intent i = new Intent(Intent.ACTION_SEND); i.setType("image/jpeg"); i.putExtra(Intent.EXTRA_SUBJECT, "Dilbert " + date + " #simpledilbert"); i.putExtra(Intent.EXTRA_TEXT, "Dilbert " + date + " #simpledilbert"); File tmp = File .createTempFile("dilbert_", ".jpg", getActivity() .getExternalCacheDir() ); FileOutputStream out = new FileOutputStream(tmp); resource.compress(CompressFormat.JPEG, 100, out); out.close(); FragmentActivity activity = getActivity(); Uri u = FileProvider.getUriForFile(activity, activity.getPackageName() + ".provider", tmp); i.putExtra(Intent.EXTRA_STREAM, u); startActivity(Intent.createChooser(i, getString(R.string.share_chooser))); } catch (Throwable e) { if (getActivity() != null) Toast.makeText(getActivity(), R.string.loading_exception_error, Toast.LENGTH_LONG).show(); } }
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { view = inflater.inflate(R.layout.fragment_about, container, false); String versionName = ""; try { versionName = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0).versionName; } catch (PackageManager.NameNotFoundException e) { // do nothing } setTextWithLinks((TextView) view.findViewById(R.id.text_application_info), getString(R.string.application_info_text, versionName)); setTextWithLinks((TextView) view.findViewById(R.id.text_developer_info), getString(R.string.developer_info_text)); setTextWithLinks((TextView) view.findViewById(R.id.text_libraries), getString(R.string.libraries_text)); setTextWithLinks((TextView) view.findViewById(R.id.text_license), getString(R.string.license_text)); return view; }
final String roomName = event.getRoomName(); Spannable roomText = new SpannableString(String.format("%1$s (Building %2$s)", roomName, Building.fromRoomName(roomName))); final int roomImageResId = getResources().getIdentifier(StringUtils.roomNameToResourceName(roomName), "drawable", getActivity().getPackageName());