Я хочу, чтобы пользователь javascript с моим кодом Android и вызывал активность в код javascript. WebView не может быть решена & не может сделать статическую ссылку на нестатический метод findViewById (INT) от типа деятельностиAndroid Webview с javascript его показать ошибку
Это таким изображение ошибки в моем андроиде коде webviwe:
public class Web extends AppCompatActivity {
private static WebView mWebView;
private static RelativeLayout mRelativeLayout;
private static ImageView mImageView;
public static Context mContext;
public static FloatingActionButton mFab;
public static ProgressBar loadingProgressBar;
public static String message;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web);
Intent intent = getIntent();
message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
mRelativeLayout = (RelativeLayout) findViewById(R.id.layout_top_rel);
mImageView = (ImageView) findViewById(R.id.no_net);
mFab = (FloatingActionButton) findViewById(R.id.fab);
mWebView = (WebView) findViewById(R.id.w1);
loadingProgressBar = (ProgressBar) findViewById(R.id.progressbar_Horizontal);
mContext = this;
mWebView.getSettings().setJavaScriptEnabled(true);
// JSInterface = new JavaScriptInterface(this);
//mWebView.addJavascriptInterface(new JavaScriptInterface(this), "JSInterface");
startME();
}
public static void startME(){
if (AppUtil.isNetworkAvailable(mContext))initScreen();
else {
mImageView.setVisibility(View.VISIBLE);
mRelativeLayout.setVisibility(View.GONE);
}
}
public class WebAppInterface {
Context mContext;
/** Instantiate the interface and set the context */
WebAppInterface(Context c) {
mContext = c;
}
/** Show a toast from the web page */
@JavascriptInterface
public void showToast(String toast) {
Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
}
}
@SuppressLint("JavascriptInterface")
public static void initScreen(){
mImageView.setVisibility(View.GONE);
mRelativeLayout.setVisibility(View.VISIBLE);
mFab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Download Android App");
shareIntent.putExtra(Intent.EXTRA_TEXT, message);
shareIntent.setType("text/plain");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
mContext.startActivity(Intent.createChooser(shareIntent, "Send using"));
}
});
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.addJavascriptInterface(new WebAppInterface(this), "android");
mWebView.loadUrl(message);
mWebView.setWebViewClient(new MyWebViewClient());
mWebView.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
loadingProgressBar.setProgress(newProgress);
if (newProgress == 100)loadingProgressBar.setVisibility(View.GONE);
else loadingProgressBar.setVisibility(View.VISIBLE);
}
});
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
mWebView.goBack();
return true;
}
else
{
Intent i = new Intent(this, MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(i);
}
return super.onKeyDown(keyCode, event);
}
private static class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
message=url;
return true;
}
}
}