将cookie传递给Firefox for Android浏览器

时间:2014-07-11 14:33:27

标签: java android firefox android-intent cookies

我有一个在我的服务器上执行post请求的方法,当成功时我的服务器返回一个cookie

List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
            nameValuePairs.add(new BasicNameValuePair("username", uname));
            nameValuePairs.add(new BasicNameValuePair("password", passwd));
            try {
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            // Execute HTTP Post Request
            try {
                  response = httpclient.execute(httppost);
                  List<Cookie> cookiejar = ((AbstractHttpClient) httpclient).getCookieStore().getCookies();
                  for (Cookie c : cookiejar)
                  {
                      cookiename=c.getName();
                      coo = c.getValue(); 

                  }
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
        }

直到这里一切正常,现在获得我要发送给Firefox的cookie之后。我尝试了以下但它似乎没有起作用。

        Intent intent = new Intent(Intent.ACTION_VIEW, null);

        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        intent.setComponent(new ComponentName("org.mozilla.firefox", "org.mozilla.firefox.App"));
        intent.setAction("org.mozilla.gecko.BOOKMARK");
        //intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        intent.putExtra("args", "--url=" + url1 );
        intent.putExtra("args", "--Cookie" + coo );
        intent.setData(Uri.parse(url1));
        Bundle b = new Bundle();
        b.putBoolean("new_window", true); //sets new window
        intent.putExtras(b);
        startActivity(intent);
}

有人可以帮我找出出错的地方吗?

0 个答案:

没有答案