我想从公共虚空中获取一个String并进入我的onCreate所以我可以记录它以检查哈希是否正常工作。但我不知道该怎么做
继承我的代码
public class ChooseTeamActivity extends ListActivity {
private static final String apiKey = "4545ggg454hfnf7557kfdkgg454";
private static final String apiUser = "AndroidUser";
long unixTimeStamp = System.currentTimeMillis() / 1000L;
String newFeedRequest = "1.0/evoStructure?timestamp=" + unixTimeStamp;
String fixturesFeedURL = "https://secure.TestSite.com/_services/api/" + newFeedRequest;
public void hash() throws NoSuchAlgorithmException, UnsupportedEncodingException{
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(fixturesFeedURL.getBytes("UTF-8"));
byte[] digest = md.digest();
String strhash = new String(digest);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.chooseact);
Log.v("myApp", fixturesFeedURL);
Log.v("myApp", strhash);
}
}
答案 0 :(得分:1)
试试这个:
public class ChooseTeamActivity extends ListActivity {
private static final String apiKey = "4545ggg454hfnf7557kfdkgg454";
private static final String apiUser = "AndroidUser";
long unixTimeStamp = System.currentTimeMillis() / 1000L;
String newFeedRequest = "1.0/evoStructure?timestamp=" + unixTimeStamp;
String fixturesFeedURL = "https://secure.TestSite.com/_services/api/" + newFeedRequest;
String strHash = null;
public void hash() throws NoSuchAlgorithmException, UnsupportedEncodingException{
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(fixturesFeedURL.getBytes("UTF-8"));
byte[] digest = md.digest();
strHash = new String(digest);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.chooseact);
hash();
Log.v("myApp", fixturesFeedURL);
Log.v("myApp", strhash);
}
}
或:
public class ChooseTeamActivity extends ListActivity {
private static final String apiKey = "4545ggg454hfnf7557kfdkgg454";
private static final String apiUser = "AndroidUser";
long unixTimeStamp = System.currentTimeMillis() / 1000L;
String newFeedRequest = "1.0/evoStructure?timestamp=" + unixTimeStamp;
String fixturesFeedURL = "https://secure.TestSite.com/_services/api/" + newFeedRequest;
public String hash() throws NoSuchAlgorithmException, UnsupportedEncodingException{
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(fixturesFeedURL.getBytes("UTF-8"));
byte[] digest = md.digest();
return new String(digest);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.chooseact);
String strhash = hash();
Log.v("myApp", fixturesFeedURL);
Log.v("myApp", strhash);
}
}
答案 1 :(得分:0)
只需将Log行放入hash()方法并从onCreate调用它:
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
hash();
}
public void hash(){
Log.v("myApp", "HelloWorld");
}
答案 2 :(得分:0)
我想你想这样做......
public class ChooseTeamActivity extends ListActivity {
private static final String apiKey = "4545ggg454hfnf7557kfdkgg454";
private static final String apiUser = "AndroidUser";
long unixTimeStamp = System.currentTimeMillis() / 1000L;
String newFeedRequest = "1.0/evoStructure?timestamp=" + unixTimeStamp;
String fixturesFeedURL = "https://secure.TestSite.com/_services/api/" + newFeedRequest;
public void hash() throws NoSuchAlgorithmException, UnsupportedEncodingException{
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(fixturesFeedURL.getBytes("UTF-8"));
byte[] digest = md.digest();
String strhash = new String(digest);
Log.v("myApp", fixturesFeedURL);
Log.v("myApp", strhash);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.chooseact);
try{
hash();
}catch(Exception e){
}
}
}
答案 3 :(得分:0)
我从你的问题中得到的是尝试使用这种方式
private static final String apiKey = "4545ggg454hfnf7557kfdkgg454";
private static final String apiUser = "AndroidUser";
String strhash="";
long unixTimeStamp = System.currentTimeMillis() / 1000L;
String newFeedRequest = "1.0/evoStructure?timestamp=" + unixTimeStamp;
String fixturesFeedURL = "https://secure.TestSite.com/_services/api/" + newFeedRequest;
public void hash() throws NoSuchAlgorithmException, UnsupportedEncodingException{
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(fixturesFeedURL.getBytes("UTF-8"));
byte[] digest = md.digest();
strhash = new String(digest);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.chooseact);
Log.v("myApp", fixturesFeedURL);
Log.v("myApp", strhash);
}}