四處串基本上我有一個獨立的類,它不使用活動或服務。 該類中的一個函數啓動一個新的Authenticator。在保護功能的Android
我在strings.xml檔案一個字符串,我想訪問 尋找最好的方法
示例代碼
class MyConnection(){
String username;
String pwd;
String strurl;
public MyConnection(String usernameIN, String pwdIN, String urlIN){
this.username = usernameIN;
this.pwd = pwdIN;
this.strurl = urlIN
}
public void
URL url = null;
try {
url = new URL(this.strURL);
URLConnection urlConn = null;
Authenticator.setDefault(new Authenticator()){
protected PasswordAuthentication getPasswordAuthentication()(
// I want my vars from strings.xml here
return new PasswordAuthentication(strUsername, strPwd.toCharArray());
}
});
urlCOnn = url.openConnection();
//Rest of the code, including CATCH
}
我通過了瓦爾地走入類,但怎麼做我訪問他們當我設置PasswordAuthentication。或者我可以直接從strings.xml訪問它們?