Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Check Permission properly #227

Merged
merged 2 commits into from
Jun 19, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Toast.makeText(getActivity().getApplicationContext(), getResources().getString(R.string.camera_permission_not_given), Toast.LENGTH_LONG).show();
somenath1435 marked this conversation as resolved.
Show resolved Hide resolved
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)
somenath1435 marked this conversation as resolved.
Show resolved Hide resolved
Toast.makeText(getActivity().getApplicationContext(), getResources().getString(R.string.storage_permission_not_given), Toast.LENGTH_LONG).show();
else {
Intent galIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galIntent, GALLERY);
}
}

@Override
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@
<string name="camera">CAMERA</string>
<string name="img_upload_success">Succesfully updated your profile picture</string>
<string name="img_upload_failure">Failed to upload your profile picture</string>
<string name="camera_permission_not_given">Camera Permission not given</string>
<string name="storage_permission_not_given">Storage Permission not given</string>

<!--Change Email Fragment-->
<string name="change_email">Change Email</string>
Expand Down