Schaggo Mikatis
Schaggo Mikatis

Reputation: 43

Java code superclass error

G'day! I started programming literally yesterday and am now stuck at an @Override snippet I would like to include in a webview based app.

the problem is, that androids browser doesn't seem to recognize "tel:"-links. to solve that I added an override at the end. Any suggestions?

Thanks

package com.example.app;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.net.Uri;
import android.content.Intent;


public class MainActivity extends Activity {


private WebView mWebView;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mWebView = (WebView) findViewById(R.id.activity_main_webview);
    mWebView.setWebViewClient(new WebViewClient());
    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    mWebView.loadUrl("file:///android_asset/index.html");
}
@Override
public void onBackPressed() {
    if (mWebView.canGoBack()) {
        mWebView.goBack();
    } else {
        super.onBackPressed();
    }
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}
@Override
public boolean shouldOverrideUrlLoading(WebView webview, String url)
{
    if (url.startsWith("tel:") || url.startsWith("sms:") || url.startsWith("smsto:") || url.startsWith("mms:") || url.startsWith("mmsto:"))
    {
        Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse(url));
        startActivity(intent);
        return true;
    }
    return false;
}
}

Upvotes: 0

Views: 91

Answers (1)

Viktor
Viktor

Reputation: 326

The thing with @Override is that you should only use that when you override a method from the superclass. In this case, you extend Activity. To use Override here, Activity needs to have that method. You should just remove the @Override and call said method in your onCreate.

Upvotes: 1

Related Questions