• 로그인 함 해보끄나?

  • Sarangnamu.net June 17, 2003
    Home Login Profile Study Open Project Q&A Google Code
    redirecting and cookie data
    Last Modify : 07 August, 2012(10:24)
    // KT 에 WEB(ABIOS) 인증을 위한 PROTOTYPE CODE... 생성...
    // 종료되는 시점을 찾기 위해 onPageFinished 에서 dcd.qook.co.kr 에 도메인을 얻은 경우
    // native 로 cookie 데이터를 전달하면 될 듯....
    // 연결에 오류가 발생한다면 onReceivedError 에서 전달하면 되고...
    
    
    package net.sarangnamu.test;
    
    import java.util.ArrayList;
    import java.util.List;
    
    import org.apache.http.HttpEntity;
    import org.apache.http.HttpResponse;
    import org.apache.http.NameValuePair;
    import org.apache.http.client.entity.UrlEncodedFormEntity;
    import org.apache.http.client.methods.HttpGet;
    import org.apache.http.client.methods.HttpPost;
    import org.apache.http.cookie.Cookie;
    import org.apache.http.impl.client.DefaultHttpClient;
    import org.apache.http.message.BasicNameValuePair;
    import org.apache.http.protocol.HTTP;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.util.Log;
    import android.webkit.CookieManager;
    import android.webkit.CookieSyncManager;
    import android.webkit.WebView;
    import android.webkit.WebViewClient;
    import android.widget.TextView;
    
    public class Test extends Activity {
        /** Called when the activity is first created. */
    	
    	
    	WebView _webview;
    	TextView _v;
    
    	private class loginChecker extends WebViewClient { 
            @Override 
            public boolean shouldOverrideUrlLoading(WebView view, String url) { 
                view.loadUrl(url); 
                return true; 
            }
    
    		@Override
    		public void onPageFinished(WebView view, String url) {
    			// TODO Auto-generated method stub
    			super.onPageFinished(view, url);
    			
    	        CookieManager.getInstance().setAcceptCookie(true);
    	        String value = CookieManager.getInstance().getCookie("http://sarangnamu.net");
    	        value += "\n" +  url;
    	        	        
    	        Log.v("@@@test@@@", value);
    	        //CookieSyncManager.getInstance().stopSync();
    	        _v.setText(value);
    		}
    
    		@Override
    		public void onReceivedError(WebView view, int errorCode,
    				String description, String failingUrl) {
    			// TODO Auto-generated method stub
    			super.onReceivedError(view, errorCode, description, failingUrl);
    		} 
        }
    	
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            
             String value = "res\n";
            _v = new TextView(this);
            
            CookieSyncManager.createInstance(this);
            CookieManager.getInstance().removeExpiredCookie();
    
    		CookieSyncManager.getInstance().startSync();
    		
            _webview = new WebView(this);
            _webview.getSettings().setJavaScriptEnabled(true);  // 웹뷰에서 자바스크립트실행가능
            _webview.loadUrl("http://sarangnamu.net/test/jump1.php");  // 페이지 지정 및 열기
            _webview.setWebViewClient(new loginChecker()); // client 설정
            
            _v.setText(value);
            setContentView(_v);        
        }
    
    	@Override
    	protected void onPause() {
    		// TODO Auto-generated method stub
    		
    		Log.v("@@@test@@@", "pause");
    		CookieSyncManager.getInstance().stopSync();
    		super.onPause();
    	}
    
    
    	@Override
    	protected void onResume() {
    		Log.v("@@@test@@@", "resume");
    		super.onResume();
    		//CookieSyncManager.getInstance().startSync();
    	}
    }
    

    Comment


    입력하3 1508232035



    Locations of visitors to this page