How to use croper in andorid.
Creating New Project.
Open android studio and create a new project.
File => New => New Project => Configure your new project => Select the form factor yours app will run on => Add an Activity to Mobile => Customize the Activity => Finish.
First we need to add Library to our project.
compile 'de.hdodenhof:circleimageview:2.1.0'
compile 'com.soundcloud.android:android-crop:1.0.1@aar'
compile 'com.jakewharton:butterknife:8.4.0'
Create Xml file in project.
Open => app => res => layout - activity_main.xml.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/preImage"
android:layout_width="144dp"
android:layout_height="144dp"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:src="@mipmap/ic_launcher"
app:civ_border_color="#ffffff"
app:civ_border_width="2dp"></de.hdodenhof.circleimageview.CircleImageView>
</RelativeLayout>
Create the Java file in project.
Open app => main => src = MainActivity.java
import android.app.ProgressDialog;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;
import com.soundcloud.android.crop.Crop;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import de.hdodenhof.circleimageview.CircleImageView;
import static journal.shibboleth.com.croperactivity.MarshMallowPermission.CAMERA_PERMISSION_REQUEST_CODE;
import static journal.shibboleth.com.croperactivity.MarshMallowPermission.EXTERNAL_STORAGE_PERMISSION_REQUEST_CODE;
public class MainActivity extends AppCompatActivity {
private static final int CAMERA_REQUEST = 108;
private String mCurrentPhotoPath = "";
private MarshMallowPermission marshMallowPermission;
CircleImageView mPreImageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mPreImageView = (de.hdodenhof.circleimageview.CircleImageView) findViewById(R.id.preImage);
mPreImageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (CheckVersions.isMarshmallow()) {
marshMallowPermission =
new MarshMallowPermission(MainActivity.this);
if (!marshMallowPermission.checkPermissionForCamera()) {
marshMallowPermission.requestPermissionForCamera();
} else {
if (!marshMallowPermission.checkPermissionForExternalStorage()) {
marshMallowPermission.requestPermissionForExternalStorage();
} else {
clickImage();
}
}
} else {
clickImage();
}
}
});
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == android.R.id.home) {
Intent returnIntent = new Intent();
setResult(RESULT_CANCELED, returnIntent);
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
switch (requestCode) {
case CAMERA_PERMISSION_REQUEST_CODE:
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
if (!marshMallowPermission.checkPermissionForExternalStorage()) {
marshMallowPermission.requestPermissionForExternalStorage();
} else {
clickImage();
}
// permission was granted, yay! Do the
// contacts-related task you need to do.
} else {
Toast.makeText(this, "Camera permission needed." +
" Please allow in App Settings for additional " +
"functionality.", Toast.LENGTH_LONG).show();
// permission denied, boo! Disable the
// functionality that depends on this permission.
}
case EXTERNAL_STORAGE_PERMISSION_REQUEST_CODE: {
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
clickImage();
// permission was granted, yay! Do the
// contacts-related task you need to do.
} else {
Toast.makeText(this, "External Storage permission needed. " +
"Please allow in App Settings for additional" +
" functionality.", Toast.LENGTH_LONG).show();
// permission denied, boo! Disable the
// functionality that depends on this permission.
}
}
// other 'case' lines to check for other
// permissions this app might request
}
}
private void clickImage() {
final CharSequence[] items = {"Take Photo Camera", "Take Photo Gallery"};
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Add Photo!");
builder.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int item) {
if (items[item].equals("Take Photo Camera")) {
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (cameraIntent.resolveActivity(getPackageManager()) != null) {
// Create the File where the photo should go
File photoFile;
photoFile = createImageFile();
// Continue only if the File was successfully created
if (photoFile != null) {
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
startActivityForResult(cameraIntent, CAMERA_REQUEST);
} else {
mCurrentPhotoPath = "";
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
}
} else if (items[item].equals("Take Photo Gallery")) {
Crop.pickImage(MainActivity.this);
}
}
});
builder.show();
}
private File createImageFile() {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File image = null;
try {
image = File.createTempFile(
imageFileName, // prefix
".jpg", // suffix
storageDir // directory
);
} catch (IOException e) {
e.printStackTrace();
}
// Save a file: path for use with ACTION_VIEW intents
if (image != null) {
mCurrentPhotoPath = "file:" + image.getAbsolutePath();
Log.i("Ihdh", "Image" + mCurrentPhotoPath);
}
return image;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent result) {
if (resultCode != RESULT_CANCELED) {
if (requestCode == Crop.REQUEST_PICK && resultCode == RESULT_OK) {
beginCrop(result.getData());
} else if (requestCode == Crop.REQUEST_CROP) {
handleCrop(resultCode, result);
} else if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
if (mCurrentPhotoPath == null || mCurrentPhotoPath.isEmpty()) {
beginCrop(result.getData());
} else {
beginCrop(Uri.parse(mCurrentPhotoPath));
}
}
}
}
private void beginCrop(Uri source) {
try {
File file = MainActivity.this.getCacheDir();
deleteDir(file);
} catch (Exception e) {
e.printStackTrace();
}
Uri destination = Uri.fromFile(new File(getCacheDir(), "cropped"));
Crop.of(source, destination).asSquare().start(this, Crop.REQUEST_CROP);
}
public static boolean deleteDir(File dir) {
if (dir != null && dir.isDirectory()) {
String[] children = dir.list();
for (String aChildren : children) {
boolean success = deleteDir(new File(dir, aChildren));
if (!success) {
return false;
}
}
}
// The directory is now empty so delete it
return dir != null && dir.delete();
}
private void handleCrop(int resultCode, Intent result) {
if (resultCode == RESULT_OK) {
try {
mPreImageView.setImageDrawable(null);
} catch (Exception e) {
e.printStackTrace();
}
try {
Log.i("CROP", "handleCrop: " + Crop.getOutput(result));
mPreImageView.setImageURI(Crop.getOutput(result));
} catch (Exception e) {
e.printStackTrace();
}
} else if (resultCode == Crop.RESULT_ERROR) {
try {
Toast.makeText(this, Crop.getError(result).getMessage(), Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
}
}
}
private String saveToInternalStorage(Bitmap bitmapImage) {
ContextWrapper cw = new ContextWrapper(getApplicationContext());
// path to /data/data/yourapp/app_data/imageDir
File directory = cw.getDir("imageDir", Context.MODE_PRIVATE);
// Create imageDir
String name = System.currentTimeMillis() + "_image.jpg";
File mypath = new File(directory, name);
FileOutputStream fos = null;
try {
fos = new FileOutputStream(mypath);
// Use the compress method on the BitMap object to write image to the OutputStream
bitmapImage.compress(Bitmap.CompressFormat.JPEG, 50, fos);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (fos != null) {
fos.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return directory.getAbsolutePath() + "/" + name;
}
}
//Check the version in this class.
Create the Java file in project.
Open app => main => src = CheckVersions.java
import android.os.Build;
public class CheckVersions {
public static boolean isMarshmallow() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M;
}
}
//Permission....
Create the Java file in project.
Open app => main => src = MarshMallowPermission.java
import android.Manifest;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.widget.Toast;
public class MarshMallowPermission {
public static final int EXTERNAL_STORAGE_PERMISSION_REQUEST_CODE = 2;
public static final int CAMERA_PERMISSION_REQUEST_CODE = 3;
Activity activity;
public MarshMallowPermission(Activity activity) {
this.activity = activity;
}
public boolean checkPermissionForExternalStorage() {
int result = ContextCompat.checkSelfPermission(activity,
Manifest.permission.WRITE_EXTERNAL_STORAGE);
return result == PackageManager.PERMISSION_GRANTED;
}
public boolean checkPermissionForCamera() {
int result = ContextCompat.checkSelfPermission(activity, Manifest.permission.CAMERA);
return result == PackageManager.PERMISSION_GRANTED;
}
public void requestPermissionForExternalStorage() {
if (ActivityCompat.shouldShowRequestPermissionRationale(activity,
Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
Toast.makeText(activity, "External Storage permission needed. " +
"Please allow in App Settings for additional" +
" functionality.", Toast.LENGTH_LONG).show();
} else {
ActivityCompat.requestPermissions(activity, new String[]{
Manifest.permission.WRITE_EXTERNAL_STORAGE},
EXTERNAL_STORAGE_PERMISSION_REQUEST_CODE);
}
}
public void requestPermissionForCamera() {
if (ActivityCompat.shouldShowRequestPermissionRationale(activity,
Manifest.permission.CAMERA)) {
Toast.makeText(activity, "Camera permission needed." +
" Please allow in App Settings for additional " +
"functionality.", Toast.LENGTH_LONG).show();
} else {
ActivityCompat.requestPermissions(activity, new String[]{
Manifest.permission.CAMERA},
CAMERA_PERMISSION_REQUEST_CODE);
}
}
}
Add Internet permission in your manifest.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission-sdk-23 android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission-sdk-23 android:name="android.permission.CAMERA" />
<activity android:name="com.soundcloud.android.crop.CropImageActivity"/>
May this code help you. Thanks!!!!!!
Creating New Project.
Open android studio and create a new project.
File => New => New Project => Configure your new project => Select the form factor yours app will run on => Add an Activity to Mobile => Customize the Activity => Finish.
First we need to add Library to our project.
compile 'de.hdodenhof:circleimageview:2.1.0'
compile 'com.soundcloud.android:android-crop:1.0.1@aar'
compile 'com.jakewharton:butterknife:8.4.0'
Create Xml file in project.
Open => app => res => layout - activity_main.xml.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/preImage"
android:layout_width="144dp"
android:layout_height="144dp"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:src="@mipmap/ic_launcher"
app:civ_border_color="#ffffff"
app:civ_border_width="2dp"></de.hdodenhof.circleimageview.CircleImageView>
</RelativeLayout>
Create the Java file in project.
Open app => main => src = MainActivity.java
import android.app.ProgressDialog;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;
import com.soundcloud.android.crop.Crop;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import de.hdodenhof.circleimageview.CircleImageView;
import static journal.shibboleth.com.croperactivity.MarshMallowPermission.CAMERA_PERMISSION_REQUEST_CODE;
import static journal.shibboleth.com.croperactivity.MarshMallowPermission.EXTERNAL_STORAGE_PERMISSION_REQUEST_CODE;
public class MainActivity extends AppCompatActivity {
private static final int CAMERA_REQUEST = 108;
private String mCurrentPhotoPath = "";
private MarshMallowPermission marshMallowPermission;
CircleImageView mPreImageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mPreImageView = (de.hdodenhof.circleimageview.CircleImageView) findViewById(R.id.preImage);
mPreImageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (CheckVersions.isMarshmallow()) {
marshMallowPermission =
new MarshMallowPermission(MainActivity.this);
if (!marshMallowPermission.checkPermissionForCamera()) {
marshMallowPermission.requestPermissionForCamera();
} else {
if (!marshMallowPermission.checkPermissionForExternalStorage()) {
marshMallowPermission.requestPermissionForExternalStorage();
} else {
clickImage();
}
}
} else {
clickImage();
}
}
});
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == android.R.id.home) {
Intent returnIntent = new Intent();
setResult(RESULT_CANCELED, returnIntent);
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
switch (requestCode) {
case CAMERA_PERMISSION_REQUEST_CODE:
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
if (!marshMallowPermission.checkPermissionForExternalStorage()) {
marshMallowPermission.requestPermissionForExternalStorage();
} else {
clickImage();
}
// permission was granted, yay! Do the
// contacts-related task you need to do.
} else {
Toast.makeText(this, "Camera permission needed." +
" Please allow in App Settings for additional " +
"functionality.", Toast.LENGTH_LONG).show();
// permission denied, boo! Disable the
// functionality that depends on this permission.
}
case EXTERNAL_STORAGE_PERMISSION_REQUEST_CODE: {
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
clickImage();
// permission was granted, yay! Do the
// contacts-related task you need to do.
} else {
Toast.makeText(this, "External Storage permission needed. " +
"Please allow in App Settings for additional" +
" functionality.", Toast.LENGTH_LONG).show();
// permission denied, boo! Disable the
// functionality that depends on this permission.
}
}
// other 'case' lines to check for other
// permissions this app might request
}
}
private void clickImage() {
final CharSequence[] items = {"Take Photo Camera", "Take Photo Gallery"};
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Add Photo!");
builder.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int item) {
if (items[item].equals("Take Photo Camera")) {
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (cameraIntent.resolveActivity(getPackageManager()) != null) {
// Create the File where the photo should go
File photoFile;
photoFile = createImageFile();
// Continue only if the File was successfully created
if (photoFile != null) {
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
startActivityForResult(cameraIntent, CAMERA_REQUEST);
} else {
mCurrentPhotoPath = "";
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
}
} else if (items[item].equals("Take Photo Gallery")) {
Crop.pickImage(MainActivity.this);
}
}
});
builder.show();
}
private File createImageFile() {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File image = null;
try {
image = File.createTempFile(
imageFileName, // prefix
".jpg", // suffix
storageDir // directory
);
} catch (IOException e) {
e.printStackTrace();
}
// Save a file: path for use with ACTION_VIEW intents
if (image != null) {
mCurrentPhotoPath = "file:" + image.getAbsolutePath();
Log.i("Ihdh", "Image" + mCurrentPhotoPath);
}
return image;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent result) {
if (resultCode != RESULT_CANCELED) {
if (requestCode == Crop.REQUEST_PICK && resultCode == RESULT_OK) {
beginCrop(result.getData());
} else if (requestCode == Crop.REQUEST_CROP) {
handleCrop(resultCode, result);
} else if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
if (mCurrentPhotoPath == null || mCurrentPhotoPath.isEmpty()) {
beginCrop(result.getData());
} else {
beginCrop(Uri.parse(mCurrentPhotoPath));
}
}
}
}
private void beginCrop(Uri source) {
try {
File file = MainActivity.this.getCacheDir();
deleteDir(file);
} catch (Exception e) {
e.printStackTrace();
}
Uri destination = Uri.fromFile(new File(getCacheDir(), "cropped"));
Crop.of(source, destination).asSquare().start(this, Crop.REQUEST_CROP);
}
public static boolean deleteDir(File dir) {
if (dir != null && dir.isDirectory()) {
String[] children = dir.list();
for (String aChildren : children) {
boolean success = deleteDir(new File(dir, aChildren));
if (!success) {
return false;
}
}
}
// The directory is now empty so delete it
return dir != null && dir.delete();
}
private void handleCrop(int resultCode, Intent result) {
if (resultCode == RESULT_OK) {
try {
mPreImageView.setImageDrawable(null);
} catch (Exception e) {
e.printStackTrace();
}
try {
Log.i("CROP", "handleCrop: " + Crop.getOutput(result));
mPreImageView.setImageURI(Crop.getOutput(result));
} catch (Exception e) {
e.printStackTrace();
}
} else if (resultCode == Crop.RESULT_ERROR) {
try {
Toast.makeText(this, Crop.getError(result).getMessage(), Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
}
}
}
private String saveToInternalStorage(Bitmap bitmapImage) {
ContextWrapper cw = new ContextWrapper(getApplicationContext());
// path to /data/data/yourapp/app_data/imageDir
File directory = cw.getDir("imageDir", Context.MODE_PRIVATE);
// Create imageDir
String name = System.currentTimeMillis() + "_image.jpg";
File mypath = new File(directory, name);
FileOutputStream fos = null;
try {
fos = new FileOutputStream(mypath);
// Use the compress method on the BitMap object to write image to the OutputStream
bitmapImage.compress(Bitmap.CompressFormat.JPEG, 50, fos);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (fos != null) {
fos.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return directory.getAbsolutePath() + "/" + name;
}
}
//Check the version in this class.
Create the Java file in project.
Open app => main => src = CheckVersions.java
import android.os.Build;
public class CheckVersions {
public static boolean isMarshmallow() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M;
}
}
//Permission....
Create the Java file in project.
Open app => main => src = MarshMallowPermission.java
import android.Manifest;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.widget.Toast;
public class MarshMallowPermission {
public static final int EXTERNAL_STORAGE_PERMISSION_REQUEST_CODE = 2;
public static final int CAMERA_PERMISSION_REQUEST_CODE = 3;
Activity activity;
public MarshMallowPermission(Activity activity) {
this.activity = activity;
}
public boolean checkPermissionForExternalStorage() {
int result = ContextCompat.checkSelfPermission(activity,
Manifest.permission.WRITE_EXTERNAL_STORAGE);
return result == PackageManager.PERMISSION_GRANTED;
}
public boolean checkPermissionForCamera() {
int result = ContextCompat.checkSelfPermission(activity, Manifest.permission.CAMERA);
return result == PackageManager.PERMISSION_GRANTED;
}
public void requestPermissionForExternalStorage() {
if (ActivityCompat.shouldShowRequestPermissionRationale(activity,
Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
Toast.makeText(activity, "External Storage permission needed. " +
"Please allow in App Settings for additional" +
" functionality.", Toast.LENGTH_LONG).show();
} else {
ActivityCompat.requestPermissions(activity, new String[]{
Manifest.permission.WRITE_EXTERNAL_STORAGE},
EXTERNAL_STORAGE_PERMISSION_REQUEST_CODE);
}
}
public void requestPermissionForCamera() {
if (ActivityCompat.shouldShowRequestPermissionRationale(activity,
Manifest.permission.CAMERA)) {
Toast.makeText(activity, "Camera permission needed." +
" Please allow in App Settings for additional " +
"functionality.", Toast.LENGTH_LONG).show();
} else {
ActivityCompat.requestPermissions(activity, new String[]{
Manifest.permission.CAMERA},
CAMERA_PERMISSION_REQUEST_CODE);
}
}
}
Add Internet permission in your manifest.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission-sdk-23 android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission-sdk-23 android:name="android.permission.CAMERA" />
<activity android:name="com.soundcloud.android.crop.CropImageActivity"/>
May this code help you. Thanks!!!!!!
No comments:
Post a Comment