홈으로 홈으로 | 무료회원가입 | 아이디/비번찾기 | 즐겨찾기
추천음악방송메인홈1대1상담음악방송청취
뽕짝아가씨(무료음악채널)
okTrot(무료음악채널)
전통가요(무료음악채널)

온라이브스토어(앱다운로드)

환상의뽕짝파티 무료음악
명작트로트메들리 무료음악
트로트메들리관광 무료음악
동영상노래방
가사검색

POP Player
신나는 고스톱
컴퓨터 오목
작은 음악다방
자동러시 웹플레이어신청

보안∵서버∵쿠키
윈도우∵프레임
이미지∵배경
시간∵달력∵계산
상태바∵타이틀바
음악∵영상
폼∵전송∵테이블
키보드∵마우스
효과∵링크∵메뉴
Script∵php
기타
PHP 강좌
윈도우관련팁
웹관련팁
홈페이지제작팁
기본강좌
레지스트리
윈도우서버
리눅스서버
Android
Webview source [Android]
2년 전
package  it.floryn90.webapp;

import  android.app.Activity;
import  android.app.ProgressDialog;
import  android.content.Intent;
import  android.graphics.Bitmap;
import  android.net.Uri;
import  android.os.Build;
import  android.os.Bundle;
import  android.os.Environment;
import  android.os.Parcelable;
import  android.provider.MediaStore;
import  android.support.v7.app.ActionBarActivity;
import  android.util.Log;
import  android.view.KeyEvent;
import  android.view.View;
import  android.webkit.ValueCallback;
import  android.webkit.WebChromeClient;
import  android.webkit.WebSettings;
import  android.webkit.WebView;
import  android.webkit.WebViewClient;
import  android.widget.Toast;

import  java.io.File;
import  java.io.IOException;
import  java.text.SimpleDateFormat;
import  java.util.Date;


public  class  MainActivity  extends  ActionBarActivity  {

        private  static  final  int  INPUT_FILE_REQUEST_CODE  =  1;
        private  static  final  int  FILECHOOSER_RESULTCODE  =  1;
        private  static  final  String  TAG  =  MainActivity.class.getSimpleName();
        private  WebView  webView;
        private  WebSettings  webSettings;
        private  ValueCallback<Uri>  mUploadMessage;
        private  Uri  mCapturedImageURI  =  null;
        private  ValueCallback<Uri[]>  mFilePathCallback;
        private  String  mCameraPhotoPath;


        @Override
        public  void  onActivityResult(int  requestCode,  int  resultCode,  Intent  data)  {
                if  (Build.VERSION.SDK_INT  >=  Build.VERSION_CODES.LOLLIPOP)  {

                        if  (requestCode  !=  INPUT_FILE_REQUEST_CODE  ||  mFilePathCallback  ==  null)  {
                                super.onActivityResult(requestCode,  resultCode,  data);
                                return;
                        }

                        Uri[]  results  =  null;

                        //  Check  that  the  response  is  a  good  one
                        if  (resultCode  ==  Activity.RESULT_OK)  {
                                if  (data  ==  null)  {
                                        //  If  there  is  not  data,  then  we  may  have  taken  a  photo
                                        if  (mCameraPhotoPath  !=  null)  {
                                                results  =  new  Uri[]{Uri.parse(mCameraPhotoPath)};
                                        }
                                }  else  {
                                        String  dataString  =  data.getDataString();
                                        if  (dataString  !=  null)  {
                                                results  =  new  Uri[]{Uri.parse(dataString)};
                                        }
                                }
                        }

                        mFilePathCallback.onReceiveValue(results);
                        mFilePathCallback  =  null;

                }  else  if  (Build.VERSION.SDK_INT  <=  Build.VERSION_CODES.KITKAT)  {
                        if  (requestCode  !=  FILECHOOSER_RESULTCODE  ||  mUploadMessage  ==  null)  {
                                super.onActivityResult(requestCode,  resultCode,  data);
                                return;
                        }

                        if  (requestCode  ==  FILECHOOSER_RESULTCODE)  {

                                if  (null  ==  this.mUploadMessage)  {
                                        return;

                                }

                                Uri  result  =  null;

                                try  {
                                        if  (resultCode  !=  RESULT_OK)  {

                                                result  =  null;

                                        }  else  {

                                                //  retrieve  from  the  private  variable  if  the  intent  is  null
                                                result  =  data  ==  null  ?  mCapturedImageURI  :  data.getData();
                                        }
                                }  catch  (Exception  e)  {
                                        Toast.makeText(getApplicationContext(),  "activity  :"  +  e,
                                                        Toast.LENGTH_LONG).show();
                                }

                                mUploadMessage.onReceiveValue(result);
                                mUploadMessage  =  null;

                        }
                }

                return;
        }

        @Override
        protected  void  onCreate(Bundle  savedInstanceState)  {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_main);


                webView  =  (WebView)  findViewById(R.id.webview);
                webSettings  =  webView.getSettings();
                webSettings.setJavaScriptEnabled(true);
                webSettings.setLoadWithOverviewMode(true);
                webSettings.setAllowFileAccess(true);
                webView.setWebViewClient(new  Client());
                webView.setWebChromeClient(new  ChromeClient());
                if  (Build.VERSION.SDK_INT  >=  19)  {
                        webView.setLayerType(View.LAYER_TYPE_HARDWARE,  null);
                }
                else  if(Build.VERSION.SDK_INT  >=11  &&  Build.VERSION.SDK_INT  <  19)  {
                        webView.setLayerType(View.LAYER_TYPE_SOFTWARE,  null);
                }

                webView.loadUrl("http://example.com");  //change  with  your  website
        }

        private  File  createImageFile()  throws  IOException  {
                //  Create  an  image  file  name
                String  timeStamp  =  new  SimpleDateFormat("yyyyMMdd_HHmmss").format(new  Date());
                String  imageFileName  =  "JPEG_"  +  timeStamp  +  "_";
                File  storageDir  =  Environment.getExternalStoragePublicDirectory(
                                Environment.DIRECTORY_PICTURES);
                File  imageFile  =  File.createTempFile(
                                imageFileName,    /*  prefix  */
                                ".jpg",                  /*  suffix  */
                                storageDir            /*  directory  */
                );
                return  imageFile;
        }

        public  class  ChromeClient  extends  WebChromeClient  {

                //  For  Android  5.0
                public  boolean  onShowFileChooser(WebView  view,  ValueCallback<Uri[]>  filePath,  WebChromeClient.FileChooserParams  fileChooserParams)  {
                        //  Double  check  that  we  don't  have  any  existing  callbacks
                        if  (mFilePathCallback  !=  null)  {
                                mFilePathCallback.onReceiveValue(null);
                        }
                        mFilePathCallback  =  filePath;

                        Intent  takePictureIntent  =  new  Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                        if  (takePictureIntent.resolveActivity(getPackageManager())  !=  null)  {
                                //  Create  the  File  where  the  photo  should  go
                                File  photoFile  =  null;
                                try  {
                                        photoFile  =  createImageFile();
                                        takePictureIntent.putExtra("PhotoPath",  mCameraPhotoPath);
                                }  catch  (IOException  ex)  {
                                        //  Error  occurred  while  creating  the  File
                                        Log.e(TAG,  "Unable  to  create  Image  File",  ex);
                                }

                                //  Continue  only  if  the  File  was  successfully  created
                                if  (photoFile  !=  null)  {
                                        mCameraPhotoPath  =  "file:"  +  photoFile.getAbsolutePath();
                                        takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                                                        Uri.fromFile(photoFile));
                                }  else  {
                                        takePictureIntent  =  null;
                                }
                        }

                        Intent  contentSelectionIntent  =  new  Intent(Intent.ACTION_GET_CONTENT);
                        contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
                        contentSelectionIntent.setType("image/*");

                        Intent[]  intentArray;
                        if  (takePictureIntent  !=  null)  {
                                intentArray  =  new  Intent[]{takePictureIntent};
                        }  else  {
                                intentArray  =  new  Intent[0];
                        }

                        Intent  chooserIntent  =  new  Intent(Intent.ACTION_CHOOSER);
                        chooserIntent.putExtra(Intent.EXTRA_INTENT,  contentSelectionIntent);
                        chooserIntent.putExtra(Intent.EXTRA_TITLE,  "Image  Chooser");
                        chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,  intentArray);

                        startActivityForResult(chooserIntent,  INPUT_FILE_REQUEST_CODE);

                        return  true;

                }

                //  openFileChooser  for  Android  3.0+
                public  void  openFileChooser(ValueCallback<Uri>  uploadMsg,  String  acceptType)  {

                        mUploadMessage  =  uploadMsg;
                        //  Create  AndroidExampleFolder  at  sdcard
                        //  Create  AndroidExampleFolder  at  sdcard

                        File  imageStorageDir  =  new  File(
                                        Environment.getExternalStoragePublicDirectory(
                                                        Environment.DIRECTORY_PICTURES)
                                        ,  "AndroidExampleFolder");

                        if  (!imageStorageDir.exists())  {
                                //  Create  AndroidExampleFolder  at  sdcard
                                imageStorageDir.mkdirs();
                        }

                        //  Create  camera  captured  image  file  path  and  name
                        File  file  =  new  File(
                                        imageStorageDir  +  File.separator  +  "IMG_"
                                                        +  String.valueOf(System.currentTimeMillis())
                                                        +  ".jpg");

                        mCapturedImageURI  =  Uri.fromFile(file);

                        //  Camera  capture  image  intent
                        final  Intent  captureIntent  =  new  Intent(
                                        android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

                        captureIntent.putExtra(MediaStore.EXTRA_OUTPUT,  mCapturedImageURI);

                        Intent  i  =  new  Intent(Intent.ACTION_GET_CONTENT);
                        i.addCategory(Intent.CATEGORY_OPENABLE);
                        i.setType("image/*");

                        //  Create  file  chooser  intent
                        Intent  chooserIntent  =  Intent.createChooser(i,  "Image  Chooser");

                        //  Set  camera  intent  to  file  chooser
                        chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS
                                        ,  new  Parcelable[]  {  captureIntent  });

                        //  On  select  image  call  onActivityResult  method  of  activity
                        startActivityForResult(chooserIntent,  FILECHOOSER_RESULTCODE);


                }

                //  openFileChooser  for  Android  <  3.0
                public  void  openFileChooser(ValueCallback<Uri>  uploadMsg)  {
                        openFileChooser(uploadMsg,  "");
                }

                //openFileChooser  for  other  Android  versions
                public  void  openFileChooser(ValueCallback<Uri>  uploadMsg,
                                                                        String  acceptType,
                                                                        String  capture)  {

                        openFileChooser(uploadMsg,  acceptType);
                }

        }

        public  boolean  onKeyDown(int  keyCode,  KeyEvent  event)  {
                //  Check  if  the  key  event  was  the  Back  button  and  if  there's  history
                if  ((keyCode  ==  KeyEvent.KEYCODE_BACK)  &&  webView.canGoBack())  {
                        webView.goBack();
                        return  true;
                }
                //  If  it  wasn't  the  Back  key  or  there's  no  web  page  history,  bubble  up  to  the  default
                //  system  behavior  (probably  exit  the  activity)

                return  super.onKeyDown(keyCode,  event);
        }


        public  class  Client  extends  WebViewClient  {
                ProgressDialog  progressDialog;

                public  boolean  shouldOverrideUrlLoading(WebView  view,  String  url)  {

                        //  If  url  contains  mailto  link  then  open  Mail  Intent
                        if  (url.contains("mailto:"))  {

                                //  Could  be  cleverer  and  use  a  regex
                                //Open  links  in  new  browser
                                view.getContext().startActivity(
                                                new  Intent(Intent.ACTION_VIEW,  Uri.parse(url)));

                                //  Here  we  can  open  new  activity

                                return  true;

                        }else  {

                                //  Stay  within  this  webview  and  load  url
                                view.loadUrl(url);
                                return  true;
                        }
                }

                //Show  loader  on  url  load
                public  void  onPageStarted(WebView  view,  String  url,  Bitmap  favicon)  {

                        //  Then  show  progress    Dialog
                        //  in  standard  case  YourActivity.this
                        if  (progressDialog  ==  null)  {
                                progressDialog  =  new  ProgressDialog(MainActivity.this);
                                progressDialog.setMessage("Loading...");
                                progressDialog.show();
                        }
                }

                //  Called  when  all  page  resources  loaded
                public  void  onPageFinished(WebView  view,  String  url)  {
                        try  {
                                //  Close  progressDialog
                                if  (progressDialog.isShowing())  {
                                        progressDialog.dismiss();
                                        progressDialog  =  null;
                                }
                        }  catch  (Exception  exception)  {
                                exception.printStackTrace();
                        }
                }
        }


}
추천추천 : 103 추천 목록
번호 제목
1,318
 구글(Google)검색에서 고급연산자를 이용하여 많은 정보를 얻는 방법
1,317
 프로그램 없이 하드디스크 복사 및 백업하기
1,316
 Windows7 업데이트 기록 삭제방법
1,315
 포토샵 psd 파일 연결 레지스트리(registry) 편집
1,314
 윈도 10 최신 업데이트 후 인터넷 속도의 저하가 발생할 때 조치 사항
1,313
 Autotuning level 해제 (윈도우비스타 이상 윈도우)인터넷 속도 빠르게 하는 방법
1,312
 윈도우에서 특정프로세스를 일괄 종료하는법
1,311
 MediaPlayer 클래스 사용법
1,310
 안드로이드에서 audio player 실행하기
1,309
 [Android] MediaPlayer 음악재생기 만들기
1,308
 Eclipse와 Android NDK 연동하기
1,307
 Android Sliding Drawer Functionality 안드로이드 슬라이딩 드로우 예제 sample
1,306
 Android Speech To Text
1,305
 Android WebPageLoader with progress-bar
1,304
 Android Text To Speech(TTS)
1,303
 Android Playing Audio from a web url
1,302
 Button height different from background height in Android image design
1,301
 Android Getting Started with Material Design
1,300
 Using toast inside timertask perfect
1,299
 네트워크 상태 [Android]
 Webview source [Android]
1,297
 공유 Intent [Android]
1,296
 intent uri 모음 [Android]
1,295
 http requestWebViewClient [Android]
1,294
 캐시 삭제
1,293
 캐시 지우기 [Android]
1,292
 바로풀어(수학 문제 질의응답 SNS) 에 사용된 오픈소스 라이브러리 [Android]
1,291
 Webviw [Android]
1,290
 오픈소스 라이브러리 모음 [Android]
1,289
 Android webview 개발시 알아둬야 할 것들 [Android]
1,288
 webview 동영상 재생 [Android]
1,287
 [Android] Webview 404 에러 처리
1,286
 [Android] webview ssl 문제
1,285
 [Android] Webview url 숨기기
1,284
 [Android] AlarmManager 일정시간 이벤트 실행
목록
인기절정뽕짝파티
인기트로트모음
지루박디스코메들리
밤무대애창곡
전자올겐경음악
세월따라노래따라
가슴시린트로트
트로트쌍쌍파티
7080추억속으로
종합성인가요방
못잊을옛날노래
카바레 음악
트롯디스코팡팡
관광 메들리
트롯카페
가요감상실
추억의옛노래
스페셜가요광장
BillBoard Free
추천가요모음
경음악.전자올겐
스페셜음악여행
WOLRD POPs
K-POP\BillBoard
JP\CN
POP TOP BEST
K.R.노래방

추천가요\인기
F뮤직 인기\발라드
F뮤직 애창\트로트
트로트성인가요
인기가요
프리미엄 POP
경음악\기타
프리미엄 최신가요
프리미엄 성인가요
가요축제\트롯1번지
댄스\메들리\리믹스
카페\명상\경음악\기타
뮤직트로트 부산광역시부산진구 가야동 ㅣ 개인정보취급방침
Copyright (C) musictrot All rights reserved.