Hey, I want to make a simple pdf webview extension but it always fails
/** ~~~~~
* Created with the AppyBuilder Code Editor.
* This is a template for basic Extension.
* Modify this template to customize your extension.
*
* **** NOTE: DO NOT use a package name.
* **** The package name will be created for you automatically.
* **** Adding a package name will cause a compile error
*/
import android.content.Context;
import android.util.Log;
import com.google.appinventor.components.annotations.*;
import com.google.appinventor.components.runtime.*;
import com.google.appinventor.components.common.ComponentCategory;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;
@UsesPermissions(permissionNames = "android.permission.INTERNET")
@DesignerComponent(version = 1, description = "This Extension was created with the AppyBuilder Code Editor.<br>" +
"Create your own here:<br><a href='https://editor.appybuilder.com' target='_blank'>https://editor.appybuilder.com</a><br>",
category = ComponentCategory.EXTENSION,
nonVisible = true, iconName = "http://appyBuilder.com/extensions/icons/extension.png")
@SimpleObject(external = true)
public class Webpdf extends AndroidNonvisibleComponent {
private ComponentContainer container;
/**
* @param container container, component will be placed in
*/
public Webpdf(ComponentContainer container) {
super(container.$form());
this.container = container;
}
@SimpleFunction(description = "")
public void PdfURL(String pdf) {
WebView webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("https://drive.google.com/viewerng/viewer?embedded=true&url=" + pdf);
}
}
}
what are you trying to do ?? does findViewById gonna work ?? as i know find by id is given in xml file res. does this id is of webview of kodular ??. and btw how you gonna get the webview with your code
Kodular uses Android x libraries, so you don’t need to use AppCompatActivity.
You use this method to find a view that you defined in the android: id XML attribute. In extension development, you should create a view programmatically. So,
WebView webview = new Webview(container.$context());
And to show the WebView in a particular arrangement provided by user, you should get an AndroidViewComponent from the user and then add the webview in that AndroidViewComponent as wangsk789 mentioned.