메뉴 건너뛰기

?

단축키

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를 띄우는 형태로 처리되어 있다. 


List of Articles
번호 제목 날짜 조회 수
197 안드로이드 스튜디오 - getter/setter 메소드 자동생성 file 2021.03.29 583
196 안드로이드 스튜디오 actionbar(액션바) 사라짐 file 2020.12.14 612
195 [Android] 퍼미션 권한체크(테드퍼미션) 2021.09.14 616
194 안드로이드 스튜디오 - 싱글톤 패턴 (SingleTon Pattenr) 클래스 자동 생성 file 2021.03.29 621
193 안드로이드 - 갤러리에서 이미지 가져오기 2021.04.02 666
192 안드로이드 - AlertDialog 사용하여 알림창 띄우는 방법 총정리 file 2021.03.31 690
191 안드로이드 - 리사이클러뷰 (RecyclerView) notifyDataSetChanged 실행 시 깜빡 거리는 현상 2021.04.02 748
190 안드로이드에서 url 주소로 이미지 바로 불러오기 (Glide 사용) 2020.12.14 759
189 Firebase - 푸시알림 보내기 (2) 2021.09.30 768
188 안드로이드 - 문자열 배열 리소스 추가하기 <string-array> file 2021.03.31 811
187 안드로이드 - RatingBar를 통해 별점주기 file 2021.04.02 848
186 안드로이드 - Json 파싱하기 file 2021.04.02 851
185 ListView 리스트뷰 연습3 - 커스텀 리스트뷰 (Custom ListView) file 2020.12.14 906
184 안드로이드 - 문자열 리소스(Resource) 추가 및 참조하기 file 2021.03.31 906
183 안드로이드 - RecyclerView의 ViewType 구분하기 file 2021.04.02 931
182 안드로이드 - 플로팅 액션 버튼(Floating Action Button) 사용법 file 2021.04.02 969
181 하이브리드앱 기본 - WebView로 웹페이지 띄우기 file 2020.12.14 1025
» WebView 작업할때 Net::ERR_UNKNOWN_URL_SCHEME 에러 발생할때 (전화걸기,문자보내기 안된다) 2020.12.14 1069
179 안드로이드 - KeyEvent(키 이벤트) 처리 file 2021.04.02 1214
178 안드로이드 - 텍스트뷰(TextView) 사용법 정리 file 2021.03.31 1251
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 13 Next
/ 13

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved