Hi guys
I wonder if anyone knows of any extensions similar to try catch. If anyone has, send it to me. Thanks.
Hi guys
I wonder if anyone knows of any extensions similar to try catch. If anyone has, send it to me. Thanks.
Something like this?
try {
//my code
} catch(Exception e) {
//Code to be executed when an error occurs while executing the try block code.Tge exception would be stored in the e variable.
}
Or do you want a new block for this,then see rogerio_rios answer
Welcome!
Good …
It could be in the category #I Want
É verdade, desculpa
Do not worry. Just write in English. And you don’t need to mark it as a solution. Just include the #Iwant tag
@Mohamed_Tamer It’s a good block to have ln Kodular, don’t you think?
Good that it was included native in Kodular, right?
#Iwant
But I’m not a Java programmer …
That would be a good option Just the category and title made me think that he is asking about an extension
Btw, shouldn’t all of the blocks do that itself, the Error Occurred event is raised when an error occurs
Ok … I didn’t think you were wrong … don’t worry … I just liked the idea of the author of the post and suggested that the author put #iwant.
Yes, the blocks should have … or can’t It ?
Ok… We wouldn’t need Try … catch … right?
We might need it for example for extensions that doesn’t use it
Exactly ! Perfect reasoning!
Thank You !
Sorry, I’m new here.
use my Test extensions java code.
package aryan.gupta.Uninstall;
import android.app.Activity;
import android.content.Intent;
import android.content.Context;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import com.google.appinventor.components.annotations.*;
import com.google.appinventor.components.common.*;
import com.google.appinventor.components.runtime.*;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import java.io.File;
import java.lang.Object;
@SimpleObject(external = true)
@DesignerComponent(category = ComponentCategory.EXTENSION, description = "Made by Aryan Gupta", nonVisible = true, version = 1)
@UsesPermissions(permissionNames = "android.permission.REQUEST_DELETE_PACKAGES")
public class Uninstall extends AndroidNonvisibleComponent {
private ComponentContainer container;
private Context context;
public Uninstall(ComponentContainer container) {
super(container.$form());
this.container = container;
}
@SimpleFunction
public void Uninstall(String packageName){
try {
Intent intent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE);
intent.setData(Uri.parse("package:"+packageName));
container.$context().startActivity(intent);
} catch (Exception e) {
//here you can call a event for Error Occurred and many more.
}
}
}
and you can use GetApk extension’s java code.