我拿不到这个。有一个运行良好的应用程序。然后我将我的 Razr Droid 更新为 ICS,情况发生了变化。
使用 Drupal 服务模块运行 Drupal 服务器。当我通过 wifi 连接时,一切正常。但是,当我通过 3g/4g 连接时,httpclient.execute() 方法需要 3-4 分钟而不是几秒钟。我将以下示例代码放在一起重新创建了问题。我应该通过 4g 添加到服务器的浏览器连接工作正常。所以我认为这不是一个简单的无线连接问题。
public class DrupalTestActivity extends Activity {
private Context mCtx;
public static long mSESSION_LIFETIME = 200000; // seconds.
final static String URL = "www.myDrupalServer.com";
final static String ENDPOINT = "rest/";
String mResponse = null;
String cookie;
TextView textView;
public class DoLogin extends AsyncTask<Void, Void, String> {
@Override
protected String doInBackground(Void... params) {
cookie = getCookie(mCtx);
return cookie;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
textView.setText(mResponse);
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.mCtx = this;
setContentView(R.layout.main);
textView = (TextView) findViewById(R.id.textView);
DoLogin task = new DoLogin();
task.execute();
}
protected String getCookie(Context ctx) {
SharedPreferences settings = PreferenceManager
.getDefaultSharedPreferences(mCtx);
Long timestamp = settings.getLong("sessionid_timestamp", 0);
Long currenttime = new Date().getTime() / 100;
String cookie = settings.getString("cookie", null);
if (cookie == null || (currenttime - timestamp) >= mSESSION_LIFETIME) {
JSONObject mUserAccount = UserAccount.getJSONUserAccount(ctx);
userLogin(mUserAccount);
return getCookie(ctx);
} else {
Log.d("COOKIE", cookie);
return cookie;
}
}
public String userLogin(JSONObject mUserAccount) {
String uri = URL + ENDPOINT + "user/login";
HttpPost httppost = new HttpPost(uri);
httppost.setHeader("Content-type", "application/json");
StringEntity se;
try {
HttpClient mHttpClient = new DefaultHttpClient();
HttpParams mHttpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(mHttpParams, 10000);
HttpConnectionParams.setSoTimeout(mHttpParams, 10000);
se = new StringEntity(mUserAccount.toString());
se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,
"application/json"));
httppost.setEntity(se);
Log.d("STATUS", "CALLING DRUPAL");
HttpResponse response = mHttpClient.execute(httppost);
Log.d("STATUS", "LOGIN COMPLETE");
mResponse = EntityUtils.toString(response.getEntity());
// save the sessid and session_name
JSONObject obj = new JSONObject(mResponse);
SharedPreferences settings = PreferenceManager
.getDefaultSharedPreferences(mCtx);
SharedPreferences.Editor editor = settings.edit();
editor.putString("cookie", obj.getString("session_name") + "="
+ obj.getString("sessid"));
editor.putLong("sessionid_timestamp",
new Date().getTime() / 100);
editor.commit();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return mResponse;
}
}
这是类UserAccount,但我真的不认为它是相关的..
public class UserAccount {
private String USER = "tester";
private String PASSWORD = "passtest";
private static Context mCtx;
public UserAccount(Context Ctx, String Username, String Password) {
mCtx = Ctx;
}
public void save(Context mCtx) {
// TODO This would really work better if we just passed in the Account
// Object
Map<String, String> mMap = new HashMap<String, String>();
mMap.put("username", USER);
mMap.put("password", PASSWORD);
SharedPreferences settings = PreferenceManager
.getDefaultSharedPreferences(mCtx);
SharedPreferences.Editor editor = settings.edit();
Iterator<?> iter = mMap.entrySet().iterator();
while (iter.hasNext()) {
@SuppressWarnings("rawtypes")
Map.Entry mEntry = (Map.Entry) iter.next();
editor.putString(mEntry.getKey().toString(), mEntry.getValue()
.toString());
}
editor.commit();
}
public static JSONObject getJSONUserAccount(Context ctx) {
SharedPreferences accountSettings = PreferenceManager
.getDefaultSharedPreferences(ctx);
String nUsername = accountSettings.getString("username", "tester");
String nPassword = accountSettings.getString("password", "dweeber");
JSONObject JSONUser = new JSONObject();
try {
JSONUser.put("password", nPassword);
JSONUser.put("username", nUsername);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return JSONUser;
}
}
wifi 连接的 LogCat 输出。
07-02 16:49:32.812: I/System.out(12001): debugger has settled (1401)
07-02 16:49:33.319: D/dalvikvm(12001): threadid=1: still suspended after undo (sc=1 dc=1)
07-02 16:49:36.921: D/STATUS(12001): CALLING DRUPAL
07-02 16:49:37.749: D/libc(12001): Forward DNS query to netd(h=www.seinetest.com.php5-22.dfw1-1.websitetestlink.com s=^)
07-02 16:49:43.046: D/STATUS(12001): LOGIN COMPLETE
时间是十几秒左右。。
3g/4g 上的 LogCat 输出
07-02 16:52:36.171: I/System.out(12759): debugger has settled (1362)
07-02 16:52:36.687: D/dalvikvm(12759): threadid=1: still suspended after undo (sc=1 dc=1)
07-02 16:52:46.171: D/STATUS(12759): CALLING DRUPAL
07-02 16:52:47.265: D/libc(12759): Forward DNS query to netd(h=www.seinetest.com.php5-22.dfw1-1.websitetestlink.com s=^)
07-02 16:53:17.569: W/IInputConnectionWrapper(12759): getExtractedText on inactive InputConnection
07-02 16:53:17.593: W/IInputConnectionWrapper(12759): getExtractedText on inactive InputConnection
07-02 16:54:38.593: W/IInputConnectionWrapper(12759): getExtractedText on inactive InputConnection
07-02 16:54:38.616: W/IInputConnectionWrapper(12759): getExtractedText on inactive InputConnection
07-02 16:56:08.921: D/STATUS(12759): LOGIN COMPLETE
更长的登录时间!!
显然,getExtractedText 是新事物,但它是原因还是结果?我在这里搜索了 IInputConnectionWrapper getExtractedText 并且有一个问题有人问它的意义是什么。它被关闭并标记为一个坏问题。:(
其他详细信息是 Verizon 运营商服务器托管在 Rackspace 云服务器电话 Verizon Droid Razr,Android 4.0.4
我真的希望我能在这里得到一些指导,否则我几个月的工作就泡汤了。非常感谢您的帮助。