It’s 8 months later, but I just ran across this.  I bet the problem was 
that you haven’t given your app the INTERNET permission.

On Sunday, January 8, 2012 1:47:53 PM UTC-8, John Goche wrote:
>
>
> Hello,
>
> I am trying to follow the code from
>
> http://www.tbray.org/ongoing/When/201x/2011/09/29/AERC
>
> I have obtained the library with:
>
> $ git clone http://code.google.com/p/aerc/
>
> but I cannot make out what the difference is between the following two 
> variables:
>
> App.ROOT_URI
> App.ROOT_URI and App.SECRET_URI
>
> These are java.net.URL instances but I cannot figure out why they would 
> have to differ in value.
>
> After adding the following   <uses-permission 
> android:name="android.permission.GET_ACCOUNTS" />
>   <uses-permission android:name="android.permission.USE_CREDENTIALS" /> 
> and fixing the code
> that uses the library I get the following error message:
>
> Checkin failed: Authentication failed:
> Authentication failed: No network connection
>
> but my wi-fi is on and working. I did see the screen prompting me to use 
> my account credentials the first
> time but not thereafter.
>
> Any ideas why it is failing?
>
>
> package com.foo.appenginetest;
>
> import java.net.URL;
>
> import android.accounts.Account;
> import android.accounts.AccountManager;
> import android.app.Activity;
> import android.app.IntentService;
> import android.content.Intent;
> import android.os.AsyncTask;
> import android.os.Bundle;
> import android.widget.TextView;
>
> class App {
>   
>   static URL ROOT_URI = null;
>   static URL SECRET_URI = null;
>   
> }
>
> public class AppEngineTestActivity extends Activity {
>
>   private Activity activity;
>   private Activity mActivity;
>
>   public void onCreate(Bundle savedInstanceState) {
>     super.onCreate(savedInstanceState);
>     
>     try {
>     App.SECRET_URI = App.ROOT_URI = new URL("http://hellodata.appspot.com
> ");
>     } catch (Exception e) {}
>     setContentView(R.layout.main);
>     mActivity = activity = this;
>     (new Worker()).execute();
>   }
>   
>   private class Worker extends AsyncTask<Void, Void, Response> {
>     
>     AppEngineClient client;
>
>     protected Response doInBackground(Void... params) {
>       AccountManager manager = AccountManager.get(activity);
>       Account[] accounts = manager.getAccountsByType("com.google");
>       client = new AppEngineClient(App.ROOT_URI, accounts[0], activity);
>       return client.get(App.SECRET_URI, null);
>     }
>
>     protected void onPostExecute(Response response) {
>       TextView text = (TextView) activity.findViewById(R.id.text);
>       if (response == null)
>         text.setText("Checkin failed: " + client.errorMessage());
>       else if ((response.status / 100) != 2)
>         text.setText("Checkin failed: " + new String(response.body));
>       else
>         text.setText("The secret is: " + new String(response.body));
>     }
>     
>   }
>
>   class PrepareUpload extends AsyncTask<Void, Void, String> { 
>     
>     URL APP_URI = App.ROOT_URI;
>     String mErrorMessage = null;
>     // ... 
>     @Override 
>     protected String doInBackground(Void... params) { 
>       
>       AccountManager manager = AccountManager.get(activity);
>       Account[] accounts = manager.getAccountsByType("com.google");
>       Account account = accounts[0];
>  
>       // ... 
>       Authenticator authent = 
> Authenticator.appEngineAuthenticator(mActivity, account, APP_URI); 
>       String authToken = authent.token(); 
>       if (authToken == null) 
>         mErrorMessage = authent.errorMessage(); 
>       return authToken;
>       
>     }
>     
>     @Override
>     protected void onPostExecute(String authToken) {
>       // ...
>       if (authToken != null) {
>         Intent intent = new Intent(mActivity, UploadService.class);
>         intent.putExtra("authtoken", authToken); startService(intent); 
>       }
>     }
>   }
>   
>   public class UploadService extends IntentService {
>     
>     public UploadService() {
>       
>       super(null);
>       
>     }
>     
>     URL APP_URI = App.ROOT_URI;
>     
>     // ... 
>     @Override 
>     protected void onHandleIntent(Intent intent) { 
>       String authToken = intent.getStringExtra("authtoken");
>       AppEngineClient client = new AppEngineClient(APP_URI, authToken, 
> this);
>       // ...
>     }
>     private void transmit(String body, AppEngineClient client, URL target) 
> {
>       //Response response = client.post(target, null, body.toByteArray());
>       Response response = client.post(target, null, body.getBytes());
>       if (response == null) error(client.errorMessage());
>       if ((response.status / 100) != 2) 
> error(getString(R.string.upload_failed) + response.status);
>     }
>     
>     private void error(String foo) { System.out.println(foo); }
>   }
>   
> }
>
> App.ROOT_URI
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to