简体   繁体   English

尝试打开告诉链接时,Android Webview应用程序崩溃

[英]Android webview app crash when trying to open tell link

Am trying to open a tel: link on android webview but it do crash my app, please how can someone help fix this or tell me what am doing wrong. 我正在尝试在android webview上打开tel:链接,但它确实使我的应用程序崩溃了,请有人如何解决此问题或告诉我做错了什么。

MyAppWebViewClient.java MyAppWebViewClient.java

package org.event2u.event2u;

import android.content.Intent;
import android.net.Uri;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MyAppWebViewClient extends WebViewClient {

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (Uri.parse(url).getHost().endsWith("event2u.org")) {
            return false;
        }
        if (url.startsWith("tel:")) {
            Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
            view.getContext().startActivity(intent);
            //view.reload();
            return true;
        }
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        view.getContext().startActivity(intent);
        return true;
    }
}

I have tried it with this code and the app doesn't crash. 我已经用此代码尝试过了,该应用程序不会崩溃。

public boolean shouldOverrideUrlLoading(WebView view, String url) {
    if (url.startsWith("tel:") || url.startsWith("sms:") || url.startsWith("smsto:") || url.startsWith("mailto:") || url.startsWith("mms:") || url.startsWith("mmsto:") || url.startsWith("market:")) {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                startActivity(intent);
                return true;
            } else {
                view.loadUrl(url);
                return true;
            }

         }
    }

I think the problem it crash is because you say this: 我认为它崩溃的问题是因为您这样说:

Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
        view.getContext().startActivity(intent);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 android-在webview应用程序中打开外部链接 - android - open external link in webview app 尝试制作基本的Webview android应用-启动时崩溃 - Trying to make a basic webview android app - crash on startup 在android应用中打开链接,而不是打开webview - open a link within android app instead of open a webview 当我在应用浏览器中的android webview中打开链接时,如何在左上方放置关闭按钮 - when i open a link in android webview in app browser how can i put close button on top left 尝试打开数据库连接以传递给Webview时,Android应用在活动时崩溃 - Android app crashes at activity when trying to open the database connection to pass to webview 在 webview Android Studio 打开链接 - open the link in webview Android Studio 单击android Webview中的链接时启动打开浏览器 - Launching a open a browser when clicking a link in android webview 尝试使用来自另一个 android 应用程序的 URL 链接打开 chrome 应用程序 - Trying to open chrome app with a URL link from another android app 当我打开它时,Android Webview 应用程序显示黑屏 - Android Webview app shows black screen when i open it 尝试通过 Firebase 接收推送通知时,Android 应用程序崩溃 - Android App crash when is trying to receive a push notification trough firebase
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM