From 2 days, I am trying to fix this problem but could not do.
I get error that cannot find symbol in one line, I have done all the necessary imports but the same
Every line goes right but this line doesn't : -
NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
My imports in extension
import android.content.Context;
import android.app.Application;
And other imports...
And here is the error code : -
NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
[javac] ^
[javac] symbol: method getApplicationContext()
Please help me if possible, I am still learning java by creating extensions for AppInventor...
Thanks.
Use container.$context()
to get context.
1 Like
container.$context()
Is there any imports? Or I can use it directly?
No special imports required just make sure ComponentContainer
is there
1 Like
I will PM you my code, can you just check what's wrong?
Kumaraswamy:
I will PM you my code
If possible paste the code here so that it can help anyone else in the future
2 Likes
I think you should send it here, it will help others in the community to learn too. and maybe someone else can help you in the same
1 Like
package com.extension.blabla.xoma;
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;
//External
import android.content.Context;
import android.app.NotificationManager;
import android.app.Application;
@DesignerComponent(version = 1,
category = ComponentCategory.EXTENSION,
description = "BlaBla",
nonVisible = true,
iconName = "https://community-appinventor-mit-edu.ezproxy.canberra.edu.au/user_avatar/community.appinventor.mit.edu/kumaraswamy_b.g/32/13770_2.png")
@SimpleObject(external = true)
public class ExtensionTemplate extends AndroidNonvisibleComponent {
public ExtensionTemplate(ComponentContainer container) {
super(container.$form());
}
@SimpleFunction(description = "BlaBla")
public void BlaBla() {
NotificationManager notificationManager = (NotificationManager) container.$context().getSystemService(Context.NOTIFICATION_SERVICE);
//Some activity...
}
}
Yes you can see my code, @Souvik_Bera & @Alaqmar_Bohori I have just problem with that line only.
Kumaraswamy:
container
The problem is obvious. From where are you accessing the container variable ? You need to declare container variable in the extension class then assign the value from the constructor.
public class ExtensionTemplate extends AndroidNonvisibleComponent {
private ComponentContainer container;
public ExtensionTemplate(ComponentContainer container) {
super(container.$form());
this.container = container;
}
1 Like
AndroidNonvisibleComponent
has form
as a protected field which serves as a context, so form.getSystemService(...)
should work.
2 Likes
Thanks @Souvik_Bera & @ewpatton now it's working
system
Closed
October 1, 2020, 2:24pm
12
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.