Android WebView shows plain text - android

I have a WebView and I load the page using webView.loadUrl("http://myurl.com") and the page gets shown correct on android 4.X but while trying on 2.X, more specifically 2.3.5 a plain text gets displayed similar to this
What might be the problem and how do I fix it? Thanks!
My full code:
public class FragmentPolicy extends SherlockFragment implements Refreshable {
private WebView webView;
private Bundle webViewBundle;
private UpdateReceiver updateReceiver;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
updateReceiver = new UpdateReceiver();
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
LinearLayout ll = (LinearLayout) inflater.inflate(R.layout.fragment_policy, container, false);
webView = (WebView) ll.findViewById(R.id.webView);
webView.setWebViewClient(new WebViewClient(){
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(url.startsWith("mailto:")){
MailTo mt = MailTo.parse(url);
Intent i = newEmailIntent(getSherlockActivity(), mt.getTo(), mt.getSubject(), mt.getBody(), mt.getCc());
startActivity(i);
view.reload();
return true;
} else {
view.loadUrl(url);
}
return true;
}
#Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
webView.stopLoading();
webView.clearView();
Log.w("test", "Could not get policy: " + description + " Errror code: " + errorCode + ". Url: " + failingUrl);
}
});
loadPolicy();
return ll;
}
private void loadPolicy(){
if (webViewBundle == null) {
Map<String, String> headers = new HashMap<String, String>();
//does not work with webview
headers.put("Content-Type", "text/html; charset=utf-8");
headers.put("Accept", "text/html");
webView.loadUrl(Utils.getBaseAPIAddr()+"getpolicyhtml", headers);
//webView.loadData(URLEncoder.encode(result).replaceAll("\\+", " "), "text/html", Encoding.UTF_8.toString());
} else {
webView.restoreState(webViewBundle);
}
}
private Intent newEmailIntent(Context context, String address, String subject, String body, String cc) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_EMAIL, new String[] {address});
intent.putExtra(Intent.EXTRA_TEXT, body);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_CC, cc);
intent.setType("message/rfc822");
return intent;
}
#Override
public void onPause() {
super.onPause();
webViewBundle = new Bundle();
webView.saveState(webViewBundle);
}
#Override
public void onResume(){
super.onResume();
LocalBroadcastManager.getInstance(getSherlockActivity()).registerReceiver(updateReceiver, new IntentFilter("update"));
}
#Override
public void onStop(){
super.onStop();
if(updateReceiver != null){
LocalBroadcastManager.getInstance(getSherlockActivity()).unregisterReceiver(updateReceiver);
}
}
#Override
public void refresh(){
loadPolicy();
}
public class UpdateReceiver extends BroadcastReceiver{
#Override
public void onReceive(Context context, Intent intent) {
loadPolicy();
}
}
}
Things I tried
*Saving the HTML to the assets folder by manually copy and pasting it there and then load the saved HTML works fine. But why cant I load it from the web?

Do like this
private class HelloWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
and then set webview client with your web view like this
web.setWebViewClient(new HelloWebViewClient());

Related

In andriod webview whatsapp button is not working

I am trying android webview but whatsapps button give an error when i want to connect whatsapp app in my mobile, the error is like - ERR_UNKNOWN_URI_SCHEME,
below are my code, please help me-
public class MainActivity extends AppCompatActivity {
private WebView mywebView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mywebView=(WebView) findViewById(R.id.webview);
mywebView.setWebViewClient(new WebViewClient());
mywebView.loadUrl("https://royalahm.com");
WebSettings webSettings=mywebView.getSettings();
webSettings.setJavaScriptEnabled(true);
}
public class mywebClient extends WebViewClient{
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon){
super.onPageStarted(view,url,favicon);
}
#Override
public boolean shouldOverrideUrlLoading(WebView view,String url){
if(url.startsWith("whatsapp:")) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);
return true;
}
return false;
}
}
#Override
public void onBackPressed(){
if(mywebView.canGoBack()) {
mywebView.goBack();
}
else{
super.onBackPressed();
}
}
}
Try This :
public class mywebClient extends WebViewClient{
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon){
super.onPageStarted(view,url,favicon);
}
#Override
public boolean shouldOverrideUrlLoading(WebView view,String url){
if( url.startsWith("http:") || url.startsWith("https:") ) {
return false;
}
try {
// Otherwise allow the OS to handle things like tel, mailto, etc.
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
}catch (Exception e){
Log.i("IvaExc",e.toString());
}
return true;
}
}

Android App Linking not working inside the WebView

When I try with the phone browser it opens the app. but not inside of the app webview.
public class WebViewPayNowFragment extends Fragment implements AdvancedWebView.Listener {
private View rootView;
private AdvancedWebView mWebView;
private String link, tid;
private class MyBrowser extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
System.out.println("asdajsda : "+url);
if (url != null && url.startsWith("ptcl://")) {
view.getContext().startActivity(
new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
return true;
} else {
return false;
}
}
}
public WebViewPayNowFragment() {
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle bundle = this.getArguments();
if (bundle != null) {
link = bundle.getString(Constants.LINK, null);
tid = bundle.getString(Constants.TRANSACTION_ID, null);
System.out.println("asdiahsdhakjshdkah : " + link);
}
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_web_view, container, false);
mWebView = rootView.findViewById(R.id.webview);
mWebView.setListener(getActivity(), this);
mWebView.setWebViewClient(new MyBrowser());
if (link != null) {
String postData = null;
try {
postData = "TransactionID=" + URLEncoder.encode(tid, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
mWebView.postUrl(link, postData.getBytes());
} else {
}
return rootView;
}
Here is my code inside the fragment.
I created a inner class extending WebViewClient. and set the setWebViewClient but im still having the problem.
Solution:
I encountered this situation myself. This is what I did:
First create a inner class and extend it with WebViewClient:
private class MyBrowser extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
....
}
}
then:
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url != null && url.startsWith("ptcl://")) {
view.getContext().startActivity(
new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
return true;
} else {
return false;
}
}
Lastly,
webView.setWebViewClient(new MyBrowser());
Try it, Hope it helps.

Can't load url with android WebView

I am loading some urls in my app using android WebView and all successful. But when i am trying to load this url:
http://dev.infibond.com/cloud/instagram?user_profile=https%3A%2F%2Fscontent.cdninstagram.com%2Ft51.2885-19%2Fs150x150%2F13534190_829691380497090_1099495058_a.jpg&user_name=infibondtest
But for some reason i am failing - "view.loadUrl(url);" in "shouldOverrideUrlLoading" doesn't show the page and doesn't load another url. just shows a white page.
The response code from the server is 304.
Before i am getting to this url, i am doing authentication with Instagram and sending the access token as a cookie.
public class CloudWebViewActivity extends ActivityBase {
public static final String TAG = "WebViewActivity";
private static final String WEB_VIEW_TOKEN = "token";
private static final String WEB_VIEW_TITLE = "title";
private static final String WEB_VIEW_URL = "url";
private ProgressBar mPbProgress;
private Toolbar mToolbar;
private String mTitle, mUrl;
public static void setInstance(Context context, String title, String url) {
Intent starter = new Intent(context, CloudWebViewActivity.class);
starter.putExtra(WEB_VIEW_TITLE, title);
starter.putExtra(WEB_VIEW_URL, url);
context.startActivity(starter);
}
// MARK: Lifecycle
protected void onCreate(Bundle savedInstanceState) {
mTitle = getIntent().getStringExtra(WEB_VIEW_TITLE);
mUrl = getIntent().getStringExtra(WEB_VIEW_URL);
super.onCreate(savedInstanceState);
AppInstance.sharedInstance().getBus().register(this);
}
#Override
protected void onResume() {
super.onResume();
AppInstance.sharedInstance().setSelf();
mToolbar.setTitle(mTitle);
mPbProgress.setVisibility(View.VISIBLE);
}
#Override
protected void onDestroy() {
super.onDestroy();
AppInstance.sharedInstance().getBus().unregister(this);
}
#SuppressLint("SetJavaScriptEnabled")
public void findViews() {
setContentView(R.layout.webview_activity);
mPbProgress = (ProgressBar) findViewById(R.id.pBProgress);
final WebView mWebView = (WebView) findViewById(R.id.webView);
if (mWebView != null) {
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setLoadWithOverviewMode(true);
mWebView.getSettings().setUseWideViewPort(true);
mWebView.setWebViewClient(webViewClient);
// Register a new JavaScript interface called HTMLOUT
mWebView.addJavascriptInterface(new MyJavaScriptInterface(), "HTMLOUT");
}
if (JavaUtils.isNotNullNotEmptyNotWhiteSpaceOnly(mUrl) && mWebView != null) {
String cookieString = WEB_VIEW_TOKEN + "=" + NetworkManager.instance().getToken();
CookieManager.getInstance().setCookie(mUrl, cookieString);
mWebView.loadUrl(mUrl);
} else {
InfiLogger.getInstance().logRemoteException(new RuntimeException("Cloud service: " + mTitle + " came with an empty/null url address"));
AndroidUtils.showToast(R.string.error_cant_load_url);
}
}
#Override
public Toolbar setToolbar() {
mToolbar = (Toolbar) findViewById(R.id.mToolbar);
if (mToolbar != null) {
mToolbar.setVisibility(View.VISIBLE);
}
return mToolbar;
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
break;
}
return super.onOptionsItemSelected(item);
}
private void handleProgressBarVisibility(String url) {
if (url.contains("login") ||
url.contains("https://api.twitter.com/oauth/authorize?oauth_token=") ||
url.contains("https://vimeo.com/log_in") ||
url.contains(".jpg")) {
mPbProgress.setVisibility(View.GONE);
} else {
mPbProgress.setVisibility(View.VISIBLE);
}
}
private final WebViewClient webViewClient = new WebViewClient() {
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
handleProgressBarVisibility(url);
String cookieString = WEB_VIEW_TOKEN + "=" + NetworkManager.instance().getToken();
CookieManager.getInstance().setCookie(mUrl, cookieString);
view.loadUrl(url);
return true;
}
#Override
public void onPageFinished(WebView view, final String url) {
if (url.startsWith("http://dev.infibond.com/api/cloud/")) {
mPbProgress.setVisibility(View.GONE);
// This call inject JavaScript into the page which just finished loading.
view.loadUrl("javascript:window.HTMLOUT.processHTML('<head>'+document.getElementsByTagName('html')[0].innerHTML+'</head>');");
}
}
#Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
AndroidUtils.showToast(error.getDescription());
} else {
AndroidUtils.showToast(R.string.gen_Something_went_wrong);
}
mPbProgress.setVisibility(View.INVISIBLE);
}
};
// An instance of this class will be registered as a JavaScript interface
class MyJavaScriptInterface {
#JavascriptInterface
#SuppressWarnings("unused")
public void processHTML(String html) {
// process the html as needed by the app
InfiLogger.d("infi", "html: " + html);
if (html.contains("code")) {
final boolean success;
if (html.contains("\"code\":200")) {
AndroidUtils.showToast(AndroidUtils.getString(R.string.cloud_sync_start) + mTitle);
success = true;
} else {
AndroidUtils.showToast(AndroidUtils.getString(R.string.gen_Something_went_wrong));
success = false;
}
AppInstance.sharedInstance().getBus().post(new CloudConnectionStateChangedBusEvent(mTitle, success));
finish();
}
}
}
}
I am not 100% sure, but it seems like you have a lot of small errors. I think the one in question is here:
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
handleProgressBarVisibility(url);
String cookieString = WEB_VIEW_TOKEN + "=" +
NetworkManager.instance().getToken();
CookieManager.getInstance().setCookie(mUrl, cookieString);
view.loadUrl(url);
return true;
}
The view.loadUrl(url) seems very wrong to me. I think you may need to change this to something like:
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getHost().equals("dev.infibond.com")) {
return false;
}
// otherwise, they are leaving the site, so open a new
// browser instead
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
view.getContext().startActivity(intent);
return true;
}
And remove the guts of what you did here. Most of it is findViews() and should not be repeated anyway. I'm guessing this is what you meant to do with
handleProgressBarVisibility(url) in the WebViewClient but I'm not really sure:
#Override
public void onLoadResource(WebView view, String url) {
handleProgressBarVisibility(url);
}

To implement horizontal progressbar

I am Trying to implement the horizontal progressbar.But I am not understanding how to implement it in my class.Now I have implemented the dialog box which is in the format of sphener,But I want it in horizontal format showing progress of activity I am downloading some contents at that time it should show the progress.
My code is
public class Loginwebview extends Activity {
WebView webview;
String url1;
Bundle bundle=null;
private ProgressDialog progressDialog;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.weblogin);
webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
bundle = new Bundle();
webview.setWebViewClient(new WebViewClient()
{
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
url1=url.toString();
bundle.putString("parameter", url1);
progressDialog = ProgressDialog.show(Loginwebview.this, "", "Loading...");
new Thread() {
public void run() {
try{
if(url1.contains("&mydownloads=true"))
{
if(url1.contains(".zip"))
{
sleep(150000);
Intent i1 = new Intent(Loginwebview.this, DownloadZipActivity.class);
i1.putExtras(bundle);
startActivityForResult(i1,0);
}
else
{
sleep(40000);
Intent i2 = new Intent(Loginwebview.this, DownloadOther.class);
i2.putExtras(bundle);
startActivityForResult(i2, 0);
}
}
else if(url1.contains("mydownloads=true"))
{
Log.d("its in Mydownloadssss",url1.toString());
Intent i3=new Intent(Loginwebview.this,Downloadlist.class);
i3.putExtras(bundle);
startActivityForResult(i3, 0);
}
}
catch(Exception e)
{
}
progressDialog.dismiss();
}
}.start();
return true;
}
public void onPageFinished(WebView view, String url1) {
Log.i("inside onpage", "Finished loading URL: " +url1);
String mainurl=url1;
}
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Log.e("onReceivedError", "Error: " + description);
}
});
webview.loadUrl("http://xxx/PublicModules/UserLoginVerify.aspx?userid=809&deviceid=DA0CE50D-0EEB-5E8E-9DCA-AED00F9BDFE5");
}
}

How to get return value from javascript in WebView of Android?

I want to get a return value from Javascript in Android. I can do it with the iPhone, but I can't with Android. I used loadUrl, but it returned void instead of an object. Can anybody help me?
Same as Keith but shorter answer
webView.addJavascriptInterface(this, "android");
webView.loadUrl("javascript:android.onData(functionThatReturnsSomething)");
And implement the function
#JavascriptInterface
public void onData(String value) {
//.. do something with the data
}
Don't forget to remove the onData from proguard list (if you have enabled proguard)
Here's a hack on how you can accomplish it:
Add this Client to your WebView:
final class MyWebChromeClient extends WebChromeClient {
#Override
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
Log.d("LogTag", message);
result.confirm();
return true;
}
}
Now in your javascript call do:
webView.loadUrl("javascript:alert(functionThatReturnsSomething)");
Now in the onJsAlert call "message" will contain the returned value.
Use addJavascriptInterface() to add a Java object to the Javascript environment. Have your Javascript call a method on that Java object to supply its "return value".
Here's what I came up with today. It's thread-safe, reasonably efficient, and allows for synchronous Javascript execution from Java for an Android WebView.
Works in Android 2.2 and up. (Requires commons-lang because I need my code snippets passed to eval() as a Javascript string. You could remove this dependency by wrapping the code not in quotation marks, but in function(){})
First, add this to your Javascript file:
function evalJsForAndroid(evalJs_index, jsString) {
var evalJs_result = "";
try {
evalJs_result = ""+eval(jsString);
} catch (e) {
console.log(e);
}
androidInterface.processReturnValue(evalJs_index, evalJs_result);
}
Then, add this to your Android activity:
private Handler handler = new Handler();
private final AtomicInteger evalJsIndex = new AtomicInteger(0);
private final Map<Integer, String> jsReturnValues = new HashMap<Integer, String>();
private final Object jsReturnValueLock = new Object();
private WebView webView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
webView = (WebView) findViewById(R.id.webView);
webView.addJavascriptInterface(new MyJavascriptInterface(this), "androidInterface");
}
public String evalJs(final String js) {
final int index = evalJsIndex.incrementAndGet();
handler.post(new Runnable() {
public void run() {
webView.loadUrl("javascript:evalJsForAndroid(" + index + ", " +
"\"" + StringEscapeUtils.escapeEcmaScript(js) + "\")");
}
});
return waitForJsReturnValue(index, 10000);
}
private String waitForJsReturnValue(int index, int waitMs) {
long start = System.currentTimeMillis();
while (true) {
long elapsed = System.currentTimeMillis() - start;
if (elapsed > waitMs)
break;
synchronized (jsReturnValueLock) {
String value = jsReturnValues.remove(index);
if (value != null)
return value;
long toWait = waitMs - (System.currentTimeMillis() - start);
if (toWait > 0)
try {
jsReturnValueLock.wait(toWait);
} catch (InterruptedException e) {
break;
}
else
break;
}
}
Log.e("MyActivity", "Giving up; waited " + (waitMs/1000) + "sec for return value " + index);
return "";
}
private void processJsReturnValue(int index, String value) {
synchronized (jsReturnValueLock) {
jsReturnValues.put(index, value);
jsReturnValueLock.notifyAll();
}
}
private static class MyJavascriptInterface {
private MyActivity activity;
public MyJavascriptInterface(MyActivity activity) {
this.activity = activity;
}
// this annotation is required in Jelly Bean and later:
#JavascriptInterface
public void processReturnValue(int index, String value) {
activity.processJsReturnValue(index, value);
}
}
On API 19+, the best way to do this is to call evaluateJavascript on your WebView:
webView.evaluateJavascript("foo.bar()", new ValueCallback<String>() {
#Override public void onReceiveValue(String value) {
// value is the result returned by the Javascript as JSON
}
});
Related answer with more detail: https://stackoverflow.com/a/20377857
The solution that #Felix Khazin suggested works, but there is one key point missing.
The javascript call should be made after the web page in the WebView is loaded. Add this WebViewClient to the WebView, along with the WebChromeClient.
Full Example:
#Override
public void onCreate(Bundle savedInstanceState) {
...
WebView webView = (WebView) findViewById(R.id.web_view);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new MyWebViewClient());
webView.setWebChromeClient(new MyWebChromeClient());
webView.loadUrl("http://example.com");
}
private class MyWebViewClient extends WebViewClient {
#Override
public void onPageFinished (WebView view, String url){
view.loadUrl("javascript:alert(functionThatReturnsSomething())");
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
}
private class MyWebChromeClient extends WebChromeClient {
#Override
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
Log.d("LogTag", message);
result.confirm();
return true;
}
}
As an alternative variant that uses a custom scheme to communicate Android native code <-> HTML/JS code. for example MRAID uses this technic[About]
MainActivity
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
WebView.setWebContentsDebuggingEnabled(true);
}
final WebView webview = new CustomWebView(this);
setContentView(webview);
webview.loadUrl("file:///android_asset/customPage.html");
webview.postDelayed(new Runnable() {
#Override
public void run() {
//Android -> JS
webview.loadUrl("javascript:showToast()");
}
}, 1000);
}
}
CustomWebView
public class CustomWebView extends WebView {
public CustomWebView(Context context) {
super(context);
setup();
}
#SuppressLint("SetJavaScriptEnabled")
private void setup() {
setWebViewClient(new AdWebViewClient());
getSettings().setJavaScriptEnabled(true);
}
private class AdWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.startsWith("customschema://")) {
//parse uri
Toast.makeText(CustomWebView.this.getContext(), "event was received", Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
}
}
customPage.html (located in the assets folded)
<!DOCTYPE html>
<html>
<head>
<title>JavaScript View</title>
<script type="text/javascript">
<!--JS -> Android-->
function showToast() {
window.location = "customschema://goto/";
}
</script>
</head>
<body>
</body>
</html>
You can do it like this:
[Activity(Label = "#string/app_name", Theme = "#style/AppTheme", MainLauncher = true)]
public class MainActivity : AppCompatActivity
{
public WebView web_view;
public static TextView textView;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
Window.AddFlags(WindowManagerFlags.Fullscreen);
Window.ClearFlags(WindowManagerFlags.ForceNotFullscreen);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.main);
web_view = FindViewById<WebView>(Resource.Id.webView);
textView = FindViewById<TextView>(Resource.Id.textView);
web_view.Settings.JavaScriptEnabled = true;
web_view.SetWebViewClient(new SMOSWebViewClient());
web_view.LoadUrl("https://stns.egyptair.com");
}
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
{
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
public class SMOSWebViewClient : WebViewClient
{
public override bool ShouldOverrideUrlLoading(WebView view, IWebResourceRequest request)
{
view.LoadUrl(request.Url.ToString());
return false;
}
public override void OnPageFinished(WebView view, string url)
{
view.EvaluateJavascript("document.getElementsByClassName('notf')[0].innerHTML;", new JavascriptResult());
}
}
public class JavascriptResult : Java.Lang.Object, IValueCallback
{
public string Result;
public void OnReceiveValue(Java.Lang.Object result)
{
string json = ((Java.Lang.String)result).ToString();
Result = json;
MainActivity.textView.Text = Result.Replace("\"", string.Empty);
}
}

Categories

Resources