我有这段代码。问题出在this.hash
或this.getHash()
。当我尝试将哈希值设置为方法checkHash()
时,Log.d
和Server
(因为checkHash()
向服务器发送值)说this.hash
为""
}。为什么this.hash
意外变空?
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(...) {
...
Connection conn = new Connection(getApplicationContext());
this.hash = this.getHash();
Log.d("OMG", this.getHash()); // returns correct HASH value
Log.d("OMG", this.hash); // returns correct hash value
String response = conn.checkHash(this.hash, device); // this method gets empty hash value
...
}
}
编辑1
public String checkHash(String hash, String device) throws ServerException, NoInternetException {
List<NameValuePair> query = new ArrayList<NameValuePair>();
Log.d("INTERNAL", hash + " / " + device);
query.add(new BasicNameValuePair("hash", hash));
query.add(new BasicNameValuePair("key", this.KEY));
query.add(new BasicNameValuePair("device", device));
query.add(new BasicNameValuePair("method", "checkHash"));
return this.post(query);
}
@覆盖 protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); 的setContentView(R.layout.activity_main);
try {
// Checking hash
String device = Settings.Secure.getString(getApplicationContext().getContentResolver(), Settings.Secure.ANDROID_ID);
Connection conn = new Connection(getApplicationContext());
this.hash = this.getHash();
Log.d("LOVEISTRUE", this.hash);
String response = conn.checkHash(this.hash, device);
Log.d("HAVEALOOK", device + " / " + response);
Log.d("HAVEALOOKRESPONSE", response);
if (response.equals("ERR")) {
Intent toProjects = new Intent(MainActivity.this, LoginActivity.class);
this.startActivity(toProjects);
}
if (response.equals("OK")) {}
} catch (Exceptions.ServerException e) {
Intent toProjects = new Intent(MainActivity.this, LoginActivity.class);
this.startActivity(toProjects);
} catch (Exceptions.NoInternetException e) {
Intent toProjects = new Intent(MainActivity.this, LoginActivity.class);
this.startActivity(toProjects);
}
}
编辑2
03-31 20:50:02.226 25129-19694 / com.morgeousorgeous.liceraptorapp D / HAVEALOOK:2cd3c4a50347752781db11734b44c4dc 03-31 20:50:02.236 25129-19694 / com.morgeousorgeous.liceraptorapp D / HAVEALOOK:2cd3c4a50347752781db11734b44c4dc 03-31 20:50:02.246 25129-19694 / com.mverallorgeous.liceraptorapp D / HAVEALOOK:2cd3c4a50347752781db11734b44c4dc 03-31 20:50:02.366 25129-25129 / com.morgeousorgeous.liceraptorapp D / dalvikvm:GC_FOR_ALLOC释放732K,10%免费8464K / 9372K,暂停13ms,总计15ms 03-31 20:50:02.376 25129-25129 / com.mmplyorgeous.liceraptorapp I / dalvikvm-heap:将堆(frag case)增长到9.844MB,用于1481024字节分配 03-31 20:50:02.396 25129-25138 / com.morgeousorgeous.liceraptorapp D / dalvikvm:GC_FOR_ALLOC释放4K,9%免费9906K / 10820K,暂停21ms,总计22ms 03-31 20:50:02.436 25129-25129 / com.morgeousorgeous.liceraptorapp D / INTERNAL:/ 5136389168f5aa53 03-31 20:50:03.546 25129-25129 / com.morgeousorgeous.liceraptorapp D / HAVEALOOK:5136389168f5aa53 / ERR1 03-31 20:50:03.546 25129-25129 / com.morgeousorgeous.liceraptorapp D / HAVEALOOKRESPONSE:ERR1