메뉴 건너뛰기

?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

하이브리드앱을 만들때 WebView 상에서 작업을 할때,

Net::ERR_UNKNOWN_URL_SCHEME

라는 메세지가 뜨고 전화걸기, 문자보내기 인텐트가 연동이 안될때, 아래의 소스를 참고하고 해결토록 하자.

private WebView webView1;
protected void onCreate(Bundle savedInstanceState) {
 
  webView1 = (WebView) findViewById(R.id.webView1);
  webView1.setWebViewClient(new WebViewClientClass());
 
  // 각종 권한 획득
  checkVerify();
 
}
 
public void checkVerify() {
 
    if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(this, Manifest.permission.INTERNET) != PackageManager.PERMISSION_GRANTED ||
            ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_NETWORK_STATE) != PackageManager.PERMISSION_GRANTED ||
            ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED ||
            ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED ||
            ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED ||             
            ContextCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
 
 
        //카메라 또는 저장공간 권한 획득 여부 확인
        if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) || ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CAMERA)) {
 
            Toast.makeText(getApplicationContext(), "권한 관련 요청을 허용해 주셔야 카메라 캡처이미지 사용등의 서비스를 이용가능합니다.", Toast.LENGTH_SHORT).show();
 
        } else if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CALL_PHONE)) {
 
            Toast.makeText(getApplicationContext(),"전화걸기 권한을 승인해 주셔야 정상적인 전화걸기 서비스가 가능합니다.",Toast.LENGTH_SHORT).show();
 
        } else {
 
            // 카메라 및 저장공간 권한 요청
            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.INTERNET, Manifest.permission.CAMERA,
                    Manifest.permission.ACCESS_NETWORK_STATE,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE,Manifest.permission.CALL_PHONE}, 1);
        }
    }
}
 
private class WebViewClientClass extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
        //Log.d("WebViewClient URL : " , request.getUrl().toString());
 
        String url = request.getUrl().toString();
        if (url.startsWith("tel:")) {
            Intent call_phone = new Intent(Intent.ACTION_CALL);
            call_phone.setData(Uri.parse(url));
 
            if (checkSelfPermission(Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
                Toast.makeText(getApplicationContext(),"전화걸기 권한을 승인해 주셔야 정상적인 전화걸기 서비스가 가능합니다.",Toast.LENGTH_SHORT).show();
                return true;
            }
            startActivity(call_phone);
        } else if (url.startsWith("sms:")){
 
            Intent intent = new Intent(Intent.ACTION_SENDTO,Uri.parse(url));
            startActivity(intent);
 
        } else if (url.startsWith("intent:")) {
 
            try {
                Intent intent = Intent.parseUri(url,Intent.URI_INTENT_SCHEME);
                Intent existPackage = getPackageManager().getLaunchIntentForPackage(intent.getPackage());
                if (existPackage != null) {
                    startActivity(intent);
                } else {
                    Intent marketIntent = new Intent(Intent.ACTION_VIEW);
                    marketIntent.setData(Uri.parse("market://details?id=" + intent.getPackage()));
                    startActivity(marketIntent);
                }
 
                return true;
            } catch (Exception e) {
                Log.d("shouldOverrideUrlLoading()","intent part Error");
                e.printStackTrace();
            }
 
 
        } else {
 
            view.loadUrl(request.getUrl().toString());
        }
 
        return true;
        //return super.shouldOverrideUrlLoading(view, request);
    }
}

 

WebViewClient 를 상속한 WebViewClientClass 에서 url 이 tel: , sms: , intent: 등의 주소로 들어올때 각각 if문안에

각각 Intent를 띄우는 형태로 처리되어 있다. 


  1. Volley 로 웹요청하고 응답받기1 - Get방식

    Date2020.12.14 Views348
    Read More
  2. Volley 로 웹요청하고 응답받기2 - Post방식 , 로그인-회원가입 (php,mysql 연동)

    Date2020.12.14 Views1431
    Read More
  3. Fragment를 통한 하단탭 예제1

    Date2020.12.14 Views242
    Read More
  4. Fragment에서 Toast 사용하기

    Date2020.12.14 Views371
    Read More
  5. Volley 이용시에 한글 깨질때 UTF-8로 변경

    Date2020.12.14 Views343
    Read More
  6. 줄바꿈 문자 치환

    Date2020.12.14 Views289
    Read More
  7. 구글맵 snippet을 두줄이상으로 구현하기

    Date2020.12.14 Views480
    Read More
  8. Volley 로 웹요청하고 응답받기3 - Get방식 , json 읽기 (php,mysql)

    Date2020.12.14 Views377
    Read More
  9. android.support.v4.content.FileProvider not found

    Date2020.12.14 Views308
    Read More
  10. WebView에서 카메라 및 이미지 업로드 (선택적용가능)

    Date2020.12.14 Views2692
    Read More
  11. WebView 작업할때 Net::ERR_UNKNOWN_URL_SCHEME 에러 발생할때 (전화걸기,문자보내기 안된다)

    Date2020.12.14 Views1067
    Read More
  12. WebView를 사용할때 HttpClient를 이용한 Session 유지

    Date2018.12.27 Views4380
    Read More
  13. 하이브리드 앱에서의 세션관리(로그인 상태 유지)

    Date2018.12.27 Views5001
    Read More
  14. MediaPlayer 클래스 사용법

    Date2018.10.02 Views1803
    Read More
  15. 위젯 업데이트 주기 빠르게 하기

    Date2018.10.02 Views2142
    Read More
  16. Android Studio에서 SQLCipher 라이브러리 추가 방법

    Date2018.10.02 Views1776
    Read More
  17. 안드로이드 WebView 에서 tel: 이 되지않는 경우.

    Date2018.10.02 Views1633
    Read More
  18. 안드로이드스택(Android Stack) 확인

    Date2016.06.10 Views7778
    Read More
  19. AndroidManifest에 선언한 메타데이터(meta-data) 가져오기

    Date2016.06.10 Views9313
    Read More
  20. 버튼(Button) 패딩 제거

    Date2016.06.10 Views7651
    Read More
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 13 Next
/ 13

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved