메뉴 건너뛰기

?

단축키

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. Effects - Animate() 메서드 (여러가지 효과 동시 처리)

    Date2014.10.16 Views30718
    Read More
  2. 안드로이드와 mysql 연동시키기. php 와 json 사용

    Date2015.07.16 Views24493
    Read More
  3. [DB] 서버/클라이언트 소켓 통신하기

    Date2015.07.13 Views20567
    Read More
  4. 월별 캘린더에 일정 입력 및 조회 기능 리스트로 추가하기

    Date2015.07.16 Views18552
    Read More
  5. 스토리보드 짜는 방법

    Date2015.07.16 Views15424
    Read More
  6. 카카오톡 대화내용 가져오기(sqlite3, chat_logs)

    Date2016.05.26 Views15145
    Read More
  7. 간단한 mp3 플레이어 만들기 , 음악넣기 , 노래재생

    Date2016.06.07 Views14628
    Read More
  8. TextureView를 이용한 카메라 Preview 좌우 반전

    Date2015.06.10 Views14236
    Read More
  9. Android Login and Registration with PHP, MySQL and SQLite

    Date2015.07.16 Views14179
    Read More
  10. 블루투스(Bluetooth) 통신에 대해 알아보자

    Date2015.07.26 Views14049
    Read More
  11. 사진찍기 및 앨범 에서 사진 가져오기!!!

    Date2014.08.28 Views13889
    Read More
  12. EditText의 글자 수 제한 걸기

    Date2015.07.16 Views13881
    Read More
  13. [DB]Android - DB 연동 기술 정리

    Date2015.07.13 Views13798
    Read More
  14. 노티피케이션(Notification) 사용법 / Notification.Builder , NotificationManager

    Date2016.06.10 Views13470
    Read More
  15. 안드로이드] 페이스북 같은 슬라이드 메뉴 만들기

    Date2015.12.15 Views12537
    Read More
  16. 안드로이드용 채팅프로그램 클라이언트(java), 서버(c#) 소스

    Date2016.05.19 Views11725
    Read More
  17. 안드로이드에서 JSP 를 사용하여 mysql 연동하기

    Date2015.07.16 Views11688
    Read More
  18. WIFI 신호세기 강도 측정하기

    Date2014.08.28 Views11243
    Read More
  19. 블루투스 및 비콘 관련 정리

    Date2015.07.26 Views10829
    Read More
  20. Android 간단한 회원 가입 폼 만들기 for Mac (PHPMyAdmin 이용)

    Date2015.07.10 Views10511
    Read More
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 13 Next
/ 13

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved