我的代码写得有些糟糕,但它已在Google Code中发布。我正在尝试建立的工作流程在这里:http://code.google.com/p/phone-to-desktop/source/browse/src/net/xisberto/phonetodesktop/PhoneToDesktopActivity.java?spec=svnd70158809aeb1ba00e26a33dc7110ade33b76427&name=google-tasks&r=d70158809aeb1ba00e26a33dc7110ade33b76427
在我的上一次尝试中,当应用程序转到以下方法时:
private void chooseAccount() {
Log.i(getPackageName(), "Starting authenticate");
AccountManager manager = AccountManager.get(getApplicationContext());
manager.getAuthTokenByFeatures(
"google.com",
"Manage your tasks",
null, PhoneToDesktopActivity.this, null, null,
new AccountManagerCallback<Bundle>() {
@Override
public void run(AccountManagerFuture<Bundle> future) {
try {
Bundle bundle = future.getResult();
//So we save the account and token
setAccountName(bundle.getString(PREF_ACCOUNT_NAME));
setAuthToken(bundle.getString(PREF_AUTH_TOKEN));
Toast.makeText(getApplicationContext(),
"Account authenticated: " +
bundle.getString(PREF_ACCOUNT_NAME) + "\n" +
bundle.getString(PREF_AUTH_TOKEN),
Toast.LENGTH_SHORT).
show();
//Then we create the list we will use
createList();
} catch (OperationCanceledException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (AuthenticatorException e) {
Log.e(getApplicationInfo().packageName, e.getMessage(), e);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
},
null);
}
我得到的只是在DDMS中没有视觉变化和这些消息:
04-18 00:59:53.187: E/net.xisberto.phonetodesktop(10488): bind failure
04-18 00:59:53.187: E/net.xisberto.phonetodesktop(10488): android.accounts.AuthenticatorException: bind failure
04-18 00:59:53.187: E/net.xisberto.phonetodesktop(10488): at android.accounts.AccountManager.convertErrorToException(AccountManager.java:1450)
04-18 00:59:53.187: E/net.xisberto.phonetodesktop(10488): at android.accounts.AccountManager.access$400(AccountManager.java:138)
04-18 00:59:53.187: E/net.xisberto.phonetodesktop(10488): at android.accounts.AccountManager$AmsTask$Response.onError(AccountManager.java:1296)
04-18 00:59:53.187: E/net.xisberto.phonetodesktop(10488): at android.accounts.IAccountManagerResponse$Stub.onTransact(IAccountManagerResponse.java:69)
04-18 00:59:53.187: E/net.xisberto.phonetodesktop(10488): at android.os.Binder.execTransact(Binder.java:339)
04-18 00:59:53.187: E/net.xisberto.phonetodesktop(10488): at dalvik.system.NativeStart.run(Native Method)
任何有用的帮助/教程/代码示例?
提前致谢。
答案 0 :(得分:3)
您使用邮件jar文件,activation.jar和其他jar文件使用,以下代码用于连接电子邮件应用程序到服务器电子邮件..
Properties props = System.getProperties();
props.setProperty("mail.store.protocol", "imaps");
props.put("mail.smtp.starttls.enable","true");
Authenticator auth = new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication(){
return new PasswordAuthentication("USEREMAILID","PASSWORD ");
}
};
sessioned= Session.getDefaultInstance(props, auth);
store = sessioned.getStore("imaps");
store.connect("smtp.gmail.com","USEREMAILID","PASSWORD ");
我希望这可以帮到你!
答案 1 :(得分:-3)
好的,我得管理身份验证。我无法理解要设置的过程和值。现在我的代码编写得更好,效果也更好。