ȸ¿ø°¡ÀԡžÆÀ̵ð/ºñ¹øã±â
ȨÀ¸·Î

Webview source [Android]
7³â Àü
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();
                        }
                }
        }


}
ÃßõÃßõ : 283 Ãßõ ¸ñ·Ï
¹øÈ£ Á¦¸ñ
1,346
À©µµ¿ì ¼­¹ö 2019 Ãë¾àÁ¡ Á¡°Ë º¸¾È
1,345
À©µµ¿ì ¼­¹ö 2019 Ãë¾àÁ¡ Á¡°Ë º¸¾È (windows server 2019)
1,344
Windows Ãë¾àÁ¡Áø´Ü º¸¾È°¡À̵å¶óÀÎ
1,343
Windows Admin Center¸¦ ÅëÇÑ ¼­¹ö °ü¸®
1,342
À©µµ¿ì ¼­¹ö¿¡¼­ ½ÇÇàµÇ´Â ¼­ºñ½º È®ÀÎ
1,341
Chrome NET::ERR CERT REVOKED ÇØ°á¹æ¹ý
1,340
cmd ¸í·É¾î (¸í·É ÇÁ·ÒÇÁÆ® ¸í·É¾î) ¸ðÀ½
1,339
Windows10 ƯÁ¤ ÇÁ·Î±×·¥(OCS 2007 R2)¿¡¼­ ÷ºÎÆÄÀÏ µå·¡±×¾Øµå·ÓÀÌ ¾È µÇ´Â Çö»ó
1,338
À©µµ¿ì ·Î±×, °ü¸® À̺¥Æ® »èÁ¦
1,337
Ŭ¸° ºÎÆÃ
1,336
Windows ±¸¼º ¿ä¼Ò ÀúÀå¼Ò¿¡¼­ ÆÄÀÏ ¼Õ»ó °Ë»ç
1,335
Windows Defender °Ë»ç ±â·Ï »èÁ¦Çϱâ
1,334
°£´ÜÇÑ À©µµ¿ì 10 Á¤Ç° ÀÎÁõ (Å©·¢ÇÁ·Î±×·¥ ÇÊ¿ä¾øÀ½)
1,333
¿À·ù³­ Æú´õ °­Á¦»èÁ¦ ¹æ¹ý
1,332
Å©·Ò¿¡¼­ Ç÷¡½Ã Ç×»ó Çã¿ëÇϵµ·Ï ¼³Á¤Çϱâ (·¹Áö½ºÆ®¸®) reg ÆÄÀÏ ¸¸µé±â
1,331
GPT µð½ºÅ©¸¦ MBR µð½ºÅ©·Î º¯È¯
1,330
MBR µð½ºÅ©¸¦ GPT µð½ºÅ©·Î º¯È¯
1,329
±¸±Û °Ë»öÀ» 200% È°¿ëÇÏ°Ô ÇØÁÖ´Â °Ë»ö ¸í·É¾î ÃÑÁ¤¸®
1,328
[Jquery] jQuery·Î ¿ìŬ¸¯ ¹æÁö, µå·¡±× ¹æÁö, ¼±Åà ¹æÁö (IE10, ÆÄÀ̾îÆø½º, Å©·Ò È®ÀÎ)
1,327
php »ç¿ëÀÚ Á¢¼ÓIP, ºê¶ó¿ìÀúÁ¤º¸, osÁ¤º¸, http, https Á¢¼ÓÇÁ·ÎÅäÄÝ ¾Ë¾Æ¿À±â
1,326
[PHP] IE ºê¶ó¿ìÀú Á¢¼Ó °ËÃâÇϱâ
1,325
À©µµ¿ì10 ½Ã½ºÅÛ ¿¹¾à ÆÄƼ¼Ç È®ÀÎ ¹× »èÁ¦
1,324
À©µµ¿ì10 º¹±¸ ÆÄƼ¼Ç »èÁ¦ ¹æ¹ý
1,323
À©µµ¿ì10 ºÎÆÃÁö¿¬ °ËÀºÈ­¸é¿¡¼­ ¸îºÐ°£ ¸Ó¹«´Â Çö»ó ÇØ°á¹æ¹ý
1,322
»ï¼º³ëÆ®ºÏ ¹ÙÀÌ¿À½º ÁøÀÔÀÌ ºÒ°¡´ÉÇÑ °æ¿ì ¹ÙÀÌ¿À½º À缳ġ¿Í NVRAM ÃʱâÈ­
1,321
ÀͽºÇ÷η¯(IE)ÀÇ ±¸±Û °Ë»ö°ø±ÞÀÚ Çѱ۷Πº¯°æ ¹æ¹ý
1,320
À©µµ¿ì 10 ±âº» ¾Û »èÁ¦ ¹× º¹±¸
1,319
meta ÅÂ±× http-equiv ¼³Á¤¹æ¹ý°ú Â÷ÀÌÁ¡
1,318
±¸±Û(Google)°Ë»ö¿¡¼­ °í±Þ¿¬»êÀÚ¸¦ ÀÌ¿ëÇÏ¿© ¸¹Àº Á¤º¸¸¦ ¾ò´Â ¹æ¹ý
1,317
ÇÁ·Î±×·¥ ¾øÀÌ Çϵåµð½ºÅ© º¹»ç ¹× ¹é¾÷Çϱâ
¸ñ·Ï
¹ÂÁ÷Æ®·ÎÆ® ºÎ»ê±¤¿ª½Ã ºÎ»êÁø±¸ °¡¾ßµ¿ ¤Ó °³ÀÎÁ¤º¸Ãë±Þ¹æħ
Copyright ¨Ï musictrot All rights reserved.