2012-04-18 4 views
0

im, желающей получить String из публичной пустоты и в мою onCreate, чтобы я мог зарегистрировать ее, чтобы проверить, работает ли хэш. но я не знаю, как это сделатьAndroid, передающий переменную из общедоступной void в 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

в вашем OnCreate называют этот хэш (метод). –

ответ

0

I думаю, что вы хотите сделать это ...

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){ 
     } 

    } 

} 
0

Просто поместите строки лога в метод хэш() и вызывать его из OnCreate:

@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 

     hash(); 

} 

public void hash(){ 
    Log.v("myApp", "HelloWorld"); 
} 
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); 



    } 

} 
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); 

}}