Activity starter code error (extension)

welcome all,
i am coding a email app(for learning purpose)
i have coded

package edu.hifiapps.Emailx;
import android.content.Context;
import android.util.Log;
import com.google.appinventor.components.annotations.;
import com.google.appinventor.components.runtime.
;

import android.app.Activity;

import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;

import android.net.Uri;

import android.text.TextUtils;

import android.util.Log;

import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.SimpleObject;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.annotations.SimpleEvent;
import com.google.appinventor.components.annotations.SimpleProperty;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.AndroidViewComponent;
import com.google.appinventor.components.runtime.ComponentContainer;
import com.google.appinventor.components.runtime.EventDispatcher;

import com.google.appinventor.components.common.PropertyTypeConstants;
import com.google.appinventor.components.common.YaVersion;

import com.google.appinventor.components.runtime.errors.YailRuntimeError;

import com.google.appinventor.components.runtime.util.AnimationUtil;
import com.google.appinventor.components.runtime.util.ErrorMessages;
import com.google.appinventor.components.runtime.util.NougatUtil;
import com.google.appinventor.components.runtime.util.YailList;

import java.io.File;

@DesignerComponent(version = 1, description = "this extension is used to make emails easy made by
" +"hifi apps. contact here-
website
",
category = ComponentCategory.EXTENSION,
nonVisible = true,
iconName = "https://i.ibb.co/pnVG9xf/picture.png")

  @SimpleObject(external = true)

public class Emailx extends AndroidNonvisibleComponent {
private ComponentContainer container;
/**
* @param container container, component will be placed in
*/
public Emailx (ComponentContainer container) {
super(container.$form());
this.container = container;
}

@SimpleFunction(description = "")
public void SendMail(String to, String subject, String mailText){
Intent i = new Intent(Intent.ACTION_SENDTO);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{to});
i.putExtra(Intent.EXTRA_SUBJECT, subject);
i.putExtra(Intent.EXTRA_TEXT , mailText);
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {

}
startActivity(i);

}
}

and got errors
[javac] C:\Users\GOD\appinventor-sources\appinventor\components\src\edu\hifiapps\Emailx\Emailx.java:68: error: cannot find symbol
[javac] startActivity(Intent.createChooser(i, "Send mail..."));
[javac] ^
[javac] symbol: method startActivity(Intent)
[javac] location: class Emailx
[javac] C:\Users\GOD\appinventor-sources\appinventor\components\src\edu\hifiapps\Emailx\Emailx.java:72: error: cannot find symbol
[javac] startActivity(i);
[javac] ^
[javac] symbol: method startActivity(Intent)
[javac] location: class Emailx
[javac] Note: Some input files use or override a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 2 errors

please help
resources

From where are you starting the intent?
You need to use context(activity) to do. like context.startActivity(INTENT)

2 Likes

You should just be patient. Devs and others have a life outside of App Inventor you know. So please don't spam this topic to get attention.

7 Likes

Sorry I did that to call just sorry

Extension Developers need to understand that Android Studio Code != AI2 Extension's code.
We can't extend Activity directly.
@HIFI_APPS Have you searched in the community before creating the topic?
I don't think so.

3 Likes

Yes I know it's not equall and searched I even replied but the topic is having no solution

I will try thanks

1 Like

Yes, if you need to access context use container.$context so the code is : container.$context.startActivity(INTENT)container.$context.`

1 Like

Will try soon I am in mobile

1 Like

Also check this :

1 Like

all worked well now
i also edited some

first a variable private Context context;
then this.context = container.$context();
now context.startActivity(i);

my code
package edu.hifiapps.Emailx;
import android.content.Context;
import android.util.Log;
import com.google.appinventor.components.annotations.;
import com.google.appinventor.components.runtime.
;

import android.app.Activity;

import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;

import android.net.Uri;

import android.text.TextUtils;

import android.util.Log;

import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.SimpleObject;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.annotations.SimpleEvent;
import com.google.appinventor.components.annotations.SimpleProperty;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.AndroidViewComponent;
import com.google.appinventor.components.runtime.ComponentContainer;
import com.google.appinventor.components.runtime.EventDispatcher;

import com.google.appinventor.components.common.PropertyTypeConstants;
import com.google.appinventor.components.common.YaVersion;

import com.google.appinventor.components.runtime.errors.YailRuntimeError;

import com.google.appinventor.components.runtime.util.AnimationUtil;
import com.google.appinventor.components.runtime.util.ErrorMessages;
import com.google.appinventor.components.runtime.util.NougatUtil;
import com.google.appinventor.components.runtime.util.YailList;

import java.io.File;

.....
@SimpleObject(external = true)
public class Emailx extends AndroidNonvisibleComponent {
private ComponentContainer container;
private Context context;
/**
* @param container container, component will be placed in
*/
public Emailx (ComponentContainer container) {
super(container.$form());
this.container = container;
this.context = container.$context();
}

@SimpleFunction(description = "")
public void SendMail(String to, String subject, String mailText){
Intent i = new Intent(Intent.ACTION_SENDTO);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{to});
i.putExtra(Intent.EXTRA_SUBJECT, subject);
i.putExtra(Intent.EXTRA_TEXT , mailText);
try {
context.startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {

}
context.startActivity(i);

}
}

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.