こんにちは Stackoverflowers!
ログイン テキスト フィールド、パスワード テキスト フィールド、およびログイン ボタンで構成される比較的単純なアプリケーションを作成しました。
私の目標は、ユーザーがログイン情報を入力してログイン ボタンに触れると、アプリケーションがユーザーを指定した Web サイトにログインさせ、別のインテントまたは WebView で開くことです。私の現在の実装では、WebView を使用して新しいアクティビティを開き、ログイン情報を渡します。新しいアクティビティのコードは次のとおりです。
setContentView(R.layout.web);
try {
//add the users login information(username/pw) to a List
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("email", "random@gmail.com"));
nameValuePairs.add(new BasicNameValuePair("password", "password1"));
//declare a new HttpClient
HttpClient httpclient = new DefaultHttpClient();
//set the HttpPost to the desire URL
HttpPost httppost = new HttpPost(URL_STRING);
//set the entity to a new UrlEncodedForm with the login info and type
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8));
//store the response
HttpResponse response = httpclient.execute(httppost);
//get the data from the response
String data = new BasicResponseHandler().handleResponse(response);
//get the webview from the xml
WebView webview = (WebView)findViewById(R.id.webView);
webview.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
return true;
}
});
//load the return website from the server
webview.loadDataWithBaseURL(httppost.getURI().toString(), data, "text/html", HTTP.UTF_8, null);
これにより、URL (https サイト) に正常にログインしてページが開きますが、Web サイトのいずれかのボタンをクリックしようとすると、WebView のログイン ページに戻り、多くは表示されません。ウェブサイトの属性 (チャート/グラフ)。
これはクッキーのことでしょうか?
新しいインテントを介してログイン情報を送信する方法はありますか? または、私の WebView 実装に対する解決策はありますか?
(これは、アプリのAndroid SSO(シングルサインオン)に関する決定的な回答が得られなかった、比較的似た(っぽい)質問です)
お時間をいただきありがとうございます!私の質問を見てくれて本当にありがとう。
編集:したがって、giseksのソリューションは、WebページをWebView内にとどめるために機能しましたが、ページ上のチャート/グラフ/その他はまだ表示されませんでした。そのためのソリューションは、WebSettingsのjavascriptを有効にするのと同じくらい簡単でした
webview.getSettings().setJavaScriptEnabled(true);
参照用の Google の WebSettings Android API は次のとおりです。
これは私を助けました、私はそれがあなたを助けることを願っています!