@Override public void onConnected(Bundle bundle) { if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // TODO: Consider calling // ActivityCompat#requestPermissions // here to request the missing permissions, and then overriding // public void onRequestPermissionsResult(int requestCode, String[] permissions, // int[] grantResults) // to handle the case where the user grants the permission. See the documentation // for ActivityCompat#requestPermissions for more details. return; } Location location = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient); if (location == null) { LocationServices.FusedLocationApi.requestLocationUpdates( mGoogleApiClient, mLocationRequest, this); } else { handleNewLocation(location); } Log.i(TAG, "Location services connected."); }
private void checkForStoragePermission(int position, SimpleItemViewHolder holder) { if (ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { getWallpaper(position); } else { if (ActivityCompat.shouldShowRequestPermissionRationale( (Activity) context, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { Snackbar.make( holder.mainView, R.string.permission_storage_rationale, Snackbar.LENGTH_INDEFINITE) .setAction( R.string.ok, new View.OnClickListener() { @Override public void onClick(View view) { ActivityCompat.requestPermissions( (Activity) context, new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_STORAGE); } }) .show(); } else { reqPos = position; ActivityCompat.requestPermissions( ((Activity) context), new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_STORAGE); } } }
// If you want location on changing place also than use below method // otherwise remove all below methods and don't implement location listener @Override public void onLocationChanged(Location arg0) { if (!working) return; Log.d("TEST", "LocationChanged"); if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { return; } l = lm.getLastKnownLocation(provider); double diff_x = Math.abs(l.getLongitude() - goList.get(active).getLongitude()) * degToM * Math.abs(Math.cos(l.getLatitude())); double diff_y = Math.abs(l.getLatitude() - goList.get(active).getLatitude()) * degToM; double dist = Math.sqrt(Math.pow(diff_x, 2) + Math.pow(diff_y, 2)); x.setText("" + diff_x); y.setText("" + diff_y); if (diff_x > TOLLERANCE || diff_y > TOLLERANCE) { currentDistance.setText( getString(R.string.activityGame_currentDistance_label, getDistance(dist))); } else { goToNextPoint(); } Log.d("ERROR", "Zginąłeś"); }
/** * Handles the requesting of the camera permission. This includes showing a "Snackbar" message of * why the permission is needed then sending the request. */ private void requestCameraPermission() { Log.w(TAG, "Camera permission not granted, requesting..."); final String[] permissions = new String[] {Manifest.permission.CAMERA}; if (!ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CAMERA)) { Log.d(TAG, "We do not need to show permission rationale"); ActivityCompat.requestPermissions(this, permissions, RC_HANDLE_CAMERA_PERM); return; } final Activity thisActivity = this; Log.i(TAG, "Showing Request Permissions Rationale"); View.OnClickListener listener = new View.OnClickListener() { @Override public void onClick(View view) { ActivityCompat.requestPermissions(thisActivity, permissions, RC_HANDLE_CAMERA_PERM); } }; Snackbar.make(mGraphicOverlay, R.string.permission_camera_rationale, Snackbar.LENGTH_INDEFINITE) .setAction(android.R.string.ok, listener) .show(); }
/** * Check if we have the GET_ACCOUNTS permission and request it if we do not. * * @return true if we have the permission, false if we do not. */ private boolean checkAccountsPermission() { final String perm = Manifest.permission.GET_ACCOUNTS; int permissionCheck = ContextCompat.checkSelfPermission(getContext(), perm); if (permissionCheck == PackageManager.PERMISSION_GRANTED) { // We have the permission return true; } else if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), perm)) { // Need to show permission rationale, display a snackbar and then request // the permission again when the snackbar is dismissed. Snackbar.make( recViewLogin.findViewById(R.id.login_layout), R.string.contacts_permission_rationale, Snackbar.LENGTH_INDEFINITE) .setAction( android.R.string.ok, new View.OnClickListener() { @Override public void onClick(View v) { // Request the permission again. ActivityCompat.requestPermissions( getActivity(), new String[] {perm}, RC_PERM_GET_ACCOUNTS); } }) .show(); return false; } else { // No explanation needed, we can request the permission. ActivityCompat.requestPermissions(getActivity(), new String[] {perm}, RC_PERM_GET_ACCOUNTS); return false; } }
void startAvatarTaker() { int permissionCheck = ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.CAMERA); if (permissionCheck == PackageManager.PERMISSION_DENIED) { // Should we show an explanation? if (ActivityCompat.shouldShowRequestPermissionRationale( getActivity(), Manifest.permission.CAMERA)) { // Show an expanation to the user *asynchronously* -- don't block // this thread waiting for the user's response! After the user // sees the explanation, try again to request the permission. Snackbar.make(mView, R.string.grant_perms, Snackbar.LENGTH_LONG).show(); } else { // No explanation needed, we can request the permission. ActivityCompat.requestPermissions( getActivity(), new String[] {Manifest.permission.CAMERA}, MY_PERMISSIONS_REQUEST_CAMERA); // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an // app-defined int constant. The callback method gets the // result of the request. } } else { startActivityForResult(getPickImageChooserIntent(), 200); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Log.d(TAG, "MainActivity - onCreate"); // Check that the Permission to read From External storage - if the checkselfPermission is null // than it means that the user has clicked on "Never Ask me again". if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { // Check if we should show the Permission RAtional behind the reason we are asking for the // Permissions if (ActivityCompat.shouldShowRequestPermissionRationale( this, Manifest.permission.READ_EXTERNAL_STORAGE)) { // Show a Fragment that explains why I need this permission } else { ActivityCompat.requestPermissions( this, new String[] {Manifest.permission.READ_EXTERNAL_STORAGE}, READ_EXTERNAL_STORAGE_REQUEST_CODE); } } // Create the List from Storage getExternalRootFolderList(); // Conect the Fragment to the Activity listFragment = new FolderViewFragment(); getSupportFragmentManager() .beginTransaction() .add(R.id.fragment_container, listFragment) .commit(); }
private void getPermission() { if (ContextCompat.checkSelfPermission(this, Manifest.permission.GET_ACCOUNTS) != PackageManager.PERMISSION_GRANTED) { if (ActivityCompat.shouldShowRequestPermissionRationale( this, Manifest.permission.GET_ACCOUNTS)) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Permission Request"); builder.setMessage( "To bring you timely alerts we would require few permissions such as account details. Please grant the permissions to continue using these features"); builder.setPositiveButton( "OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); ActivityCompat.requestPermissions( MainActivity.this, new String[] {Manifest.permission.GET_ACCOUNTS}, MY_PERMISSIONS_REQUEST_GET_ACCOUNTS); } }); builder.create().show(); } else { ActivityCompat.requestPermissions( this, new String[] {Manifest.permission.GET_ACCOUNTS}, MY_PERMISSIONS_REQUEST_GET_ACCOUNTS); } } else { setupUser(); } }
@TargetApi(Build.VERSION_CODES.M) @Override public void onMapReady(GoogleMap map) { // Add a marker in Sydney, Australia, and move the camera. try { map.setMyLocationEnabled(true); } catch (Exception e) { statusCheck(); } map.getUiSettings().setCompassEnabled(true); LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // TODO: Consider calling // ActivityCompat#requestPermissions // here to request the missing permissions, and then overriding // public void onRequestPermissionsResult(int requestCode, String[] permissions, // int[] grantResults) // to handle the case where the user grants the permission. See the documentation // for ActivityCompat#requestPermissions for more details. return; } Location location = locationManager.getLastKnownLocation(locationManager.getBestProvider(criteria, false)); /*LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); Location location = locationManager.getLastKnownLocation(locationManager.getBestProvider(criteria, false)); if (location != null) { map.animateCamera(CameraUpdateFactory.newLatLngZoom( new LatLng(location.getLatitude(), location.getLongitude()), 13)); CameraPosition cameraPosition = new CameraPosition.Builder() .target(new LatLng(location.getLatitude(), location.getLongitude())) // Sets the center of the map to location user .zoom(16) // Sets the zoom .tilt(10) // Sets the tilt of the camera to 30 degrees .build(); // Creates a CameraPosition from the builder map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));*/ ctx = this.getApplicationContext(); t = new TestAdapter(ctx); Bundle extras = getIntent().getExtras(); String tag = null; System.out.println("hi this is tag extra"); if (extras != null) { tag = extras.getString("tag2"); // The key argument here must match that used in the other activity System.out.println(tag); try { LoadingGoogleMap(t.getCordinates(tag), map); System.out.println("cordinates are done"); } catch (NullPointerException e) { e.printStackTrace(); } } }
private boolean checkLocationAccessPermission() { return ActivityCompat.checkSelfPermission( getActivity(), android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission( getActivity(), android.Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED; }
@SuppressWarnings("SameParameterValue") private void perm(String permission, int permission_request) { if (ContextCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED) { if (!ActivityCompat.shouldShowRequestPermissionRationale(this, permission)) { ActivityCompat.requestPermissions(this, new String[] {permission}, permission_request); } } }
public void requestInternetPermission() { if (ActivityCompat.shouldShowRequestPermissionRationale( activity, Manifest.permission.INTERNET)) { permissionCallback.onPermissionExplanationRequired(true, Manifest.permission.INTERNET); } else { ActivityCompat.requestPermissions( activity, new String[] {Manifest.permission.INTERNET}, INTERNET_PERMISSION); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_round_tab); ButterKnife.bind(this); mNavigationBar .setDisplayBackButton(true) .setBackButtonImageResource(R.drawable.ic_chevron_left_white_24dp) .setBackButtonText("Back") .setOnBackButtonClickListener( new View.OnClickListener() { @Override public void onClick(View v) { onBackPressed(); } }) .addItem(0, "Settings", ActivityCompat.getDrawable(this, R.drawable.ic_settings_white_24dp)) .addItem(1, "More", ActivityCompat.getDrawable(this, R.drawable.ic_more_vert_white_24dp)) .setOnMenuItemClickListener( new NavigationBar.OnMenuItemClickListener() { @Override public void onMenuItemClick(int id) { Toast.makeText(getApplicationContext(), "" + id, Toast.LENGTH_SHORT).show(); } }) .setTabs(new String[] {"music", "video", "games"}) .setOnTabCheckedListener( new NavigationBar.OnTabCheckedListener() { @Override public void onTabChecked(int position) { Toast.makeText( getApplicationContext(), "Tab " + position + " is checked", Toast.LENGTH_SHORT) .show(); } }) .bindViewPager(mViewPager); mFragmentList.add(TabFragment.newInstance(TAB_NANES[0])); mFragmentList.add(TabFragment.newInstance(TAB_NANES[1])); mFragmentList.add(TabFragment.newInstance(TAB_NANES[2])); mViewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager()); mViewPager.setAdapter(mViewPagerAdapter); mSearchView.setImeOption(EditorInfo.IME_ACTION_SEARCH); mSearchView.setOnEditorActionListener(mOnEditorActionListener); mSearchView.setOnFocusChangeListener(mOnFocusChangeListener); mSearchView.setButtonTextColor(BG_COLOR); mSearchView.setHint("Search"); mSearchView.setHintTextColor(0xFF8E8E93); mSearchView.setButtonText("Cancel"); mSearchView.setStyle(SearchView.Style.ROUND); }
private boolean doNeedPermission() { if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { requestPermission(); return true; } return false; }
public boolean checkGplusPermission() { // Verify that all required contact permissions have been granted. if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.GET_ACCOUNTS) != PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.INTERNET) != PackageManager.PERMISSION_GRANTED) { return false; } return true; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.bind(this); mProgressBar.setVisibility(View.INVISIBLE); Log.d(TAG, "ProgressBar set to invisible"); locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Log.d(TAG, "Location Manager setup."); if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // TODO: Consider calling // ActivityCompat#requestPermissions // here to request the missing permissions, and then overriding // public void onRequestPermissionsResult(int requestCode, String[] permissions, // int[] grantResults) // to handle the case where the user grants the permission. See the documentation // for ActivityCompat#requestPermissions for more details. Log.d(TAG, "Inside main IF block"); double latitude = 12.903238; double longitude = 77.647602; Log.d(TAG, "Lat =" + latitude + " Long= " + longitude); Toast.makeText(MainActivity.this, R.string.loc_perm_unavailable_msg, Toast.LENGTH_LONG) .show(); // return; } else { Log.d(TAG, "Inside ELSE block"); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); Log.d(TAG, "real-time location retrieved"); } // Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); // setSupportActionBar(toolbar); mRefreshImage.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { getForecast(latitude, longitude); } }); getForecast(latitude, longitude); Log.d(TAG, "This is running on Main thread"); }
/** * Requests the fine location permission. If a rationale with an additional explanation should be * shown to the user, displays a dialog that triggers the request. */ public static void requestPermission( AppCompatActivity activity, int requestId, String permission, boolean finishActivity) { if (ActivityCompat.shouldShowRequestPermissionRationale(activity, permission)) { // Display a dialog with rationale. RationaleDialog.newInstance(requestId, finishActivity) .show(activity.getSupportFragmentManager(), "dialog"); } else { // Location permission has not been granted yet, request it. ActivityCompat.requestPermissions(activity, new String[] {permission}, requestId); } }
public void requestExternalStoragePermission() { if (ActivityCompat.shouldShowRequestPermissionRationale( activity, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { permissionCallback.onPermissionExplanationRequired( true, Manifest.permission.WRITE_EXTERNAL_STORAGE); } else { ActivityCompat.requestPermissions( activity, new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE}, EXTERNAL_STORAGE_PERMISSION); } }
private void requestPermissionForCameraAndMicrophone() { if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CAMERA) || ActivityCompat.shouldShowRequestPermissionRationale( this, Manifest.permission.RECORD_AUDIO)) { Toast.makeText(this, R.string.permissions_needed, Toast.LENGTH_LONG).show(); } else { ActivityCompat.requestPermissions( this, new String[] {Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO}, CAMERA_MIC_PERMISSION_REQUEST_CODE); } }
public void browse(View view) { // browse = R.id.browse; if (ActivityCompat.checkSelfPermission( Create_Assignment.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions( Create_Assignment.this, new String[] {Manifest.permission.READ_EXTERNAL_STORAGE}, STORAGE_PERMISSION_RC); return; } new FileChooserDialog.Builder(this).show(); }
public static boolean checkPermission(Activity activity, String permission, int code) { if (ContextCompat.checkSelfPermission(activity, permission) != PackageManager.PERMISSION_GRANTED) { if (ActivityCompat.shouldShowRequestPermissionRationale(activity, permission)) { ActivityCompat.requestPermissions(activity, new String[] {permission}, code); } else { ActivityCompat.requestPermissions(activity, new String[] {permission}, code); } return false; } return true; }
public void requestExternalStoragePermission( AppCompatActivity appCompatActivity, PermissionCallback callback, boolean requestFromDialog) { if (ActivityCompat.shouldShowRequestPermissionRationale( appCompatActivity, Manifest.permission.WRITE_EXTERNAL_STORAGE) && !requestFromDialog) { callback.onPermissionExplanationRequired(true, Manifest.permission.WRITE_EXTERNAL_STORAGE); } else { ActivityCompat.requestPermissions( appCompatActivity, new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE}, EXTERNAL_STORAGE_PERMISSION); } }
private void requestGplusPermission() { final String[] PERMISSIONS = {Manifest.permission.GET_ACCOUNTS, Manifest.permission.INTERNET}; if (ActivityCompat.shouldShowRequestPermissionRationale( getActivity(), Manifest.permission.GET_ACCOUNTS) || ActivityCompat.shouldShowRequestPermissionRationale( getActivity(), Manifest.permission.INTERNET)) { // Provide an additional rationale to the user if the permission was not granted // and the user would benefit from additional context for the use of the permission. // For example, if the request has been denied previously. String fab_skin = (BaseActivity.accentSkin); final MaterialDialog materialDialog = Futils.showBasicDialog( getActivity(), fab_skin, theme, new String[] { getResources().getString(R.string.grantgplus), getResources().getString(R.string.grantper), getResources().getString(R.string.grant), getResources().getString(R.string.cancel), null }); materialDialog .getActionButton(DialogAction.POSITIVE) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { ActivityCompat.requestPermissions(getActivity(), PERMISSIONS, 66); materialDialog.dismiss(); } }); materialDialog .getActionButton(DialogAction.NEGATIVE) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { getActivity().finish(); } }); materialDialog.setCancelable(false); materialDialog.show(); } else { // Contact permissions have not been granted yet. Request them directly. ActivityCompat.requestPermissions(getActivity(), PERMISSIONS, 66); } }
public void onConnected(Bundle connectionHint) { if (ActivityCompat.checkSelfPermission( this.getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission( this.getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { return; } mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient); if (mLastLocation != null) { latitude = mLastLocation.getLatitude(); longitude = mLastLocation.getLongitude(); } }
private void requestLocationPermission() { if (checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { if (!ActivityCompat.shouldShowRequestPermissionRationale( this, Manifest.permission.ACCESS_COARSE_LOCATION)) { // User Denied and selected "Don't ask again" --> Show info that he needs to go to settings showSettingsDialog(); } else { ActivityCompat.requestPermissions( this, MainActivity.PERMISSIONS_LOCATION, MainActivity.REQUEST_LOCATION); } } else { Snackbar.make(mLayout, "You already have this permission, FOOL!", Snackbar.LENGTH_SHORT); } }
private void requestNetworkStatePermission() { // Permission has not been granted and must be requested. /** * if (ActivityCompat.shouldShowRequestPermissionRationale(this, * Manifest.permission.ACCESS_NETWORK_STATE)) { // Provide an additional rationale to the user * if the permission was not granted // and the user would benefit from additional context for * the use of the permission. // Display a SnackBar with a button to request the missing * permission. Snackbar.make(mLayout, "Permission Access Network State is Required.", * Snackbar.LENGTH_INDEFINITE).setAction("OK", new View.OnClickListener() { @Override public * void onClick(View view) { // Request the permission * ActivityCompat.requestPermissions(MainActivity.this, new * String[]{Manifest.permission.ACCESS_NETWORK_STATE}, PERMISSION_REQUEST_NETWORK_STATE); } * }).show(); * * <p>} else { Snackbar.make(mLayout, "Permission Access Network State is not available. * Requesting permission.", Snackbar.LENGTH_SHORT).show(); // Request the permission. The result * will be received in onRequestPermissionResult(). ActivityCompat.requestPermissions(this, new * String[]{Manifest.permission.ACCESS_NETWORK_STATE}, PERMISSION_REQUEST_NETWORK_STATE); } */ if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.INTERNET)) { // Provide an additional rationale to the user if the permission was not granted // and the user would benefit from additional context for the use of the permission. // Display a SnackBar with a button to request the missing permission. Snackbar.make(mLayout, "Permission Internet is Required.", Snackbar.LENGTH_INDEFINITE) .setAction( "OK", new View.OnClickListener() { @Override public void onClick(View view) { // Request the permission ActivityCompat.requestPermissions( MainActivity.this, new String[] {Manifest.permission.INTERNET}, PERMISSION_REQUEST_INTERNET); } }) .show(); } else { Snackbar.make( mLayout, "Internet is not available. Requesting permission.", Snackbar.LENGTH_SHORT) .show(); // Request the permission. The result will be received in onRequestPermissionResult(). ActivityCompat.requestPermissions( this, new String[] {Manifest.permission.INTERNET}, PERMISSION_REQUEST_INTERNET); } }
public boolean onSupportNavigateUp() { Intent upIntent = getSupportParentActivityIntent(); if (upIntent != null) { if (supportShouldUpRecreateTask(upIntent)) { TaskStackBuilder b = TaskStackBuilder.create(this); onCreateSupportNavigateUpTaskStack(b); onPrepareSupportNavigateUpTaskStack(b); b.startActivities(); try { ActivityCompat.finishAffinity(this); } catch (IllegalStateException e) { // This can only happen on 4.1+, when we don't have a parent or a result set. // In that case we should just finish(). finish(); } } else { // This activity is part of the application's task, so simply // navigate up to the hierarchical parent activity. supportNavigateUpTo(upIntent); } return true; } return false; }
@Override public void startForResult(int requestCode) { if (fragmentSupport_ != null) { fragmentSupport_.startActivityForResult(intent, requestCode); } else { if (fragment_ != null) { if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) { fragment_.startActivityForResult(intent, requestCode, lastOptions); } else { fragment_.startActivityForResult(intent, requestCode); } } else { if (context instanceof Activity) { Activity activity = ((Activity) context); ActivityCompat.startActivityForResult(activity, intent, requestCode, lastOptions); } else { if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) { context.startActivity(intent, lastOptions); } else { context.startActivity(intent); } } } } }
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.location_activity); // Locate UI widgets mStartUpdatesButton = (Button) findViewById(R.id.start_updates_button); mStopUpdatesButton = (Button) findViewById(R.id.stop_updates_button); mLatitudeTextView = (TextView) findViewById(R.id.latitude_text); mLongitudeTextView = (TextView) findViewById(R.id.longitude_text); mLastUpdateTextView = (TextView) findViewById(R.id.last_update_text); // Set labels. mLatitudeLabel = getResources().getString(R.string.latitude_label); mLongitudeLabel = getResources().getString(R.string.longitude_label); mLastUpdateLabel = getResources().getString(R.string.last_update_time_label); mRequestingLocationUpdates = true; // Update values using data stored in the Bundle. updateValuesFromBundle(savedInstanceState); if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions( this, new String[] {Manifest.permission.ACCESS_FINE_LOCATION}, MY_PERMISSIONS_REQUEST_FINE_LOCATION); } // Kick off the process of building a GoogleApiClient and requesting the LocationServices // API. buildGoogleApiClient(); }
private void launchPostTransitionAnimations() { if (LUtils.hasL()) { ActivityCompat.setEnterSharedElementCallback( this, new SharedElementCallback() { @Override public void onSharedElementEnd( List<String> sharedElementNames, List<View> sharedElements, List<View> sharedElementSnapshots) { binding.detailsContainer.postDelayed( () -> { binding.detailsContainer.startAnimation( LUtils.loadAnimationWithLInterpolator( ProjectDetailsActivity.this, R.anim.slide_from_top)); binding.scrollView.startAnimation( LUtils.loadAnimationWithLInterpolator( ProjectDetailsActivity.this, R.anim.slide_from_top_long)); }, 0); } }); } // categoriesRv.post(() -> // categoriesRv.startAnimation(LUtils.loadAnimationWithLInterpolator(getApplicationContext(), // R.anim.slide_from_bottom))); }