Skip to content

Commit

Permalink
fix: Check Permission properly (#227)
Browse files Browse the repository at this point in the history
* Check Permission properly

* recheck permission
  • Loading branch information
somenath1435 authored and atm1504 committed Jun 19, 2019
1 parent 31ee997 commit 391c850
Showing 1 changed file with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
Expand All @@ -16,6 +18,7 @@
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.util.Base64;
import android.view.KeyEvent;
import android.view.LayoutInflater;
Expand Down Expand Up @@ -85,7 +88,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
sharedPreferenceEditor = PreferenceManager.getDefaultSharedPreferences(getActivity()).edit();

employment_type_position= spinnerEmploymentTypeArrayAdapter.getPosition(preferences.getString(Constant.EMPLOYEMENT_TYPE,""));
employment_type_position = spinnerEmploymentTypeArrayAdapter.getPosition(preferences.getString(Constant.EMPLOYEMENT_TYPE, ""));

setupViews(rootView);
setUpUi();
Expand Down Expand Up @@ -343,13 +346,23 @@ public void onClick(DialogInterface dialog,
}

private void getPhotoFromCamera() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, CAMERA);
if (ContextCompat.checkSelfPermission(getActivity().getApplicationContext(), Manifest.permission.CAMERA)
== PackageManager.PERMISSION_DENIED)
makeRequest();
else {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, CAMERA);
}
}

private void choosePhotoFromGallery() {
Intent galIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galIntent, GALLERY);
if (ContextCompat.checkSelfPermission(getActivity().getApplicationContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_DENIED)
makeRequest();
else {
Intent galIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galIntent, GALLERY);
}
}

@Override
Expand Down

0 comments on commit 391c850

Please sign in to comment.