Access Denied (only for developer)

“”""""
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import android.os.StrictMode;
import android.util.Log;
import android.widget.Toast;
import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.SimpleEvent;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.annotations.SimpleObject;
import com.google.appinventor.components.annotations.SimpleProperty;
import com.google.appinventor.components.annotations.UsesPermissions;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.runtime.ActivityResultListener;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.Component;
import com.google.appinventor.components.runtime.ComponentContainer;
import com.google.appinventor.components.runtime.Deleteable;
import com.google.appinventor.components.runtime.EventDispatcher;
import java.io.File;

@SimpleObject(external = true)
@DesignerComponent(category = ComponentCategory.EXTENSION, description = “Cropping extension created by SHUVO.”, iconName = “http://voltscdn.weebly.com/uploads/2/0/8/1/20817010/idea.png”, nonVisible = true, version = 1)
@UsesPermissions(permissionNames = “android.permission.WRITE_EXTERNAL_STORAGE, android.permission.READ_EXTERNAL_STORAGE”)
public class Cropper_img extends AndroidNonvisibleComponent implements ActivityResultListener, Component, Deleteable {
private static final String LOG_TAG = “Crop”;
public static int aspectX;
public static int aspectY;
public static String fileName;
public static String imagePath;
public final int REQUEST_CODE = this.form.registerForActivityResult(this);
private ComponentContainer container;
private Context context;

public Cropper_img(ComponentContainer container2) {
    super(container2.$form());
    this.container = container2;
    Log.d(LOG_TAG, "Crop Created");
    StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().build());
}

@SimpleProperty
public void Path(String path) {
    imagePath = "file://" + path;
}

@SimpleFunction
public void DoCrop(String filename) {
    fileName = filename;
    Uri picture = Uri.parse(imagePath);
    File file = new File(Environment.getExternalStorageDirectory(), fileName);
    try {
        Intent intent = new Intent("com.android.camera.action.CROP");
        intent.setDataAndType(picture, "image/*");
        intent.putExtra("crop", "true");
        intent.putExtra("return-data", true);
        intent.putExtra("output", Uri.parse("file://" + file.toString()));
        this.container.$context().startActivityForResult(intent, this.REQUEST_CODE);
    } catch (ActivityNotFoundException e) {
        Toast.makeText(this.context, "Corresponding activity not found.", 0).show();
    }
}

@SimpleEvent
public void AfterCrop(String path) {
    EventDispatcher.dispatchEvent(this, "AfterCrop", new Object[]{path});
}

public void resultReturned(int requestCode, int resultCode, Intent data) {
    if (requestCode == this.REQUEST_CODE && data != null) {
        AfterCrop("" + Uri.parse(new File(Environment.getExternalStorageDirectory(), fileName).toString()).toString());
    }
}

public void onDelete() {
    this.form.unregisterForActivityResult(this);
}

}
“””"""
I am using this code.
and when I write “filename” to “somethin/myfile.jpg”
then i got an error called access denied. Can any developer help me?

Dangerous permissions need to be requested in the runtime, just adding them to the manifest using usespermissions annotation isn’t enough.for example the WRITE_EXTERNAL_STORAGE permission.Take a look at the Image component to know how you should ask:

P.S: for questions about extension development, you should ask in the app Inventor community:

The #discuss category is used for discussion about kodular :slightly_smiling_face:

3 Likes

everything gone up from my head. I don’t know java yet. Is there enything that i can write/edit and problem will be fixed?

1 Like

Please ask in the App Inventor Community.

3 Likes