Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
241 views
in Technique[技术] by (71.8m points)

mailto: links unsupported in Android?

I dont have a real Android device so I'm using emulators for all my development for now, are mailto: web links really unsupported on Android devices 2.1 and below? 2.2 works, but every time I click a mailto: link on 1.6 or 2.1 even, I get an [unsupported action] dialog. Anybody with a real device want to test this out?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You have to handle it yourself in a WebViewClient

public class MyWebViewClient extends WebViewClient {
    Activity mContext;
    public MyWebViewClient(Activity context){
        this.mContext = context;
    }
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {     
        if(url.startsWith("mailto:")){
            MailTo mt = MailTo.parse(url);
            Intent i = new Intent(Intent.ACTION_SEND);
            i.setType("text/plain");
            i.putExtra(Intent.EXTRA_EMAIL, new String[]{mt.getTo()});
            i.putExtra(Intent.EXTRA_SUBJECT, mt.getSubject());
            i.putExtra(Intent.EXTRA_CC, mt.getCc());
            i.putExtra(Intent.EXTRA_TEXT, mt.getBody());
            mContext.startActivity(i);
            view.reload();
            return true;
        }
        view.loadUrl(url);
        return true;
    }
}

In your activity you keep a reference to MyWebViewClient and assign it to your webview with setWebViewClient(mWebClient).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...