안드로이드에서 웹뷰를 사용할때 서버스크립에서 표시하는 팝업이 안보여진다.

이때 해결책은 바로... 팝업이 보여줄수 있는 시간을 확보하는것이다.


아래는 팝업이 보여지는 웹뷰의 간단한 예이다.

proxyWebChromeClient를 추가하면 팝업이 보여진다.


<< WebViewActivity.java >>
public class WebViewActivity extends BaseActivity{
   	Context mContext;
           WebView webview = null;
           private String mURL = null;
           protected ProxyWebChromeClient proxyWebChromeClient;

	public static void invokeActivity(Activity activity, int viewid, String url) {
		mViewid = viewid;
		Intent intent = new Intent(activity, WebViewActivity.class);
		intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		intent.putExtra("url", url);
		activity.startActivity(intent);		
		activity.overridePendingTransition(0,0);
	}	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mContext = this;
		setContentView(R.layout.activity_webview);
		getIntentParam();
	}

	private void getIntentParam() { 
		Intent intent = getIntent();
		mURL = intent.getStringExtra("url");	// url
	}	

	@Override
	protected void onResume() {
		super.onResume();
		mContext = this;
               ...

	  webview = (WebView)findViewById(R.id.webview_contents);
	        
        //  정보 수신
         webview.setWebViewClient(new DailyWebViewClient());  // WebViewClient 지정
 	proxyWebChromeClient = new ProxyWebChromeClient();	// proxy를 사용하여 팝업이 표시될 수 있도록 처리
 	webview.setWebChromeClient(proxyWebChromeClient);

        WebSettings webSettings = webview.getSettings();
        webSettings.setSavePassword(true);
        webSettings.setSaveFormData(true);
        webSettings.setPluginsEnabled(true);
        webSettings.setUseWideViewPort(true);
        webSettings.setJavaScriptEnabled(true);
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
        webSettings.setAllowFileAccess(true);  
        webSettings.setSupportZoom(true);    // 줌지원
        webSettings.setBuiltInZoomControls(true);	// -/+ 확대 축소 버튼
        webview.setInitialScale(100); // 100%로 확대
         webview.loadUrl(mURL);  
	}		

    private class DailyWebViewClient extends WebViewClient {
    	private boolean timeout;
    	public DailyWebViewClient(){
    		timeout = true;
    	}
        @Override 
        public boolean shouldOverrideUrlLoading(WebView view, String url) { 
        	view.loadUrl(url); 
            return true; 
        } 
        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {     
        	super.onReceivedError(view, errorCode, description, failingUrl);
        	if(C.D)Log.d(C.TAG,"errorCode="+errorCode+", description="+description+", failingUrl="+failingUrl);
			if(mMyLoadingDialog != null){
				mMyLoadingDialog.dismiss();
			}
        }

		@Override
		public void onPageStarted(WebView view, String url, Bitmap favicon) {
			super.onPageStarted(view, url, favicon);
				if(mMyLoadingDialog == null){
					mMyLoadingDialog = new MyLoadingDialog(mContext);
					
					if(!mMyLoadingDialog.isShowing()){	// 보여지는중이 아니면 보여주기
						mMyLoadingDialog.show();
					}					
				}
				new Thread(new Runnable(){

					@Override
					public void run() {
	                      try {                     
	                    	  Thread.sleep(5000);                 
	                      } catch (InterruptedException e) {                      
	                    	  e.printStackTrace(); 
	                      }
		                  if(timeout){                     
		            			if(mMyLoadingDialog != null){
		            				mMyLoadingDialog.dismiss();
		            			}
		                  }    
					}
					
				}).start();
		
				return;
								
		} 
        
		@Override
		public void onPageFinished(WebView view, String url) {
			super.onPageFinished(view, url);
			if(mMyLoadingDialog != null){
				mMyLoadingDialog.dismiss();
			}

		}        
        
    }

	protected class ProxyWebChromeClient extends WebChromeClient {
		// 팝업 표시를 위한 proxy

	}    

	@Override
	public void onBackPressed() {
	    // 누적된 history를 저장할 변수
	    WebBackForwardList list = webview.copyBackForwardList();
	 
	    if (list.getCurrentIndex() <= 0 && !webview.canGoBack()) {
	        // 처음 들어온 페이지이거나, history가 없는경우
	        super.onBackPressed();
	    } else {
	        // history가 있는 경우
	        // 현재 페이지로 부터 history 수 만큼 뒷 페이지로 이동
	    	webview.goBackOrForward(-(list.getCurrentIndex()));
	        // history 삭제
	    	webview.clearHistory();
	    }		

		if(mMyLoadingDialog != null){
			mMyLoadingDialog.dismiss();
		}			
	}	
}

<< activity_webview.xml >>


<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    android:orientation="vertical"

    android:background="#ffffff">

    

<WebView

   android:id="@+id/webview_contents"

   android:layout_width="fill_parent"

   android:layout_height="0dp"

   android:layout_weight="1"

   android:scrollbars="vertical" />

</LinearLayout>


+ Recent posts