I have only just encountered this so was wondering if anyone else had. The Android oAuth library starts another activity and that activity causes a NetworkOnMainThreadException. Apparently network access on the UI thread used to be allowed, but starting with Honeycomb this exception is thrown. As far as I can tell at the moment, the Android oAuth library will not work on Honeycomb (and probably above).
However, I had to create a local copy of the oAuth library for another reason, so I could be missing a fix. Am I?
Android oAuth service throws NetworkOnMainThreadException
Started by Martin Harvey, Jun 28 2012 04:01 PM
android oauth
4 replies to this topic
#1
Posted 28 June 2012 - 04:01 PM
#2
Posted 28 June 2012 - 05:05 PM
Turns out that, something called StrictMode was introduced in Gingerbread and turned off by default. However, in HoneyComb 'StrictMode' is turned on. This prevents network access on the UI thread. This allows the following workaround (discouraged obviously)...
In class EvernoteOAuthActivity (package: com.evernote.client.oauth.android of the oAuth library) add the following lines in the onCreate method:
public void onCreate(Bundle savedInstanceState) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
You could presumably use permitNetwork() instead of permitAll(). I am running with this until a permanent fix is available. Since this is only invoked when authenticating (which could be as little as once every 365 days) I don't think it is a problem.
Maybe I will get my devCup submission in on time after all...!
In class EvernoteOAuthActivity (package: com.evernote.client.oauth.android of the oAuth library) add the following lines in the onCreate method:
public void onCreate(Bundle savedInstanceState) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
You could presumably use permitNetwork() instead of permitAll(). I am running with this until a permanent fix is available. Since this is only invoked when authenticating (which could be as little as once every 365 days) I don't think it is a problem.
Maybe I will get my devCup submission in on time after all...!
#3
Posted 29 June 2012 - 02:08 PM
FYI: The above fix does not support Froyo so I used the method shown here to implement version dependent code.
A (probably should be abstract) class implements the permitAll() method...
The Froyo implementation does nothing (in the end it is not needed)...
The Honeycomb implementation disables strict mode...
The EvernoteOAuthActivity then instantiates the appropriate class depending on the version:
A (probably should be abstract) class implements the permitAll() method...
public class VersionedStrictPolicy {
VersionedStrictPolicy() {
}
public void permitAll() {
}
}The Froyo implementation does nothing (in the end it is not needed)...
public class FroyoStrictPolicy extends VersionedStrictPolicy {
}The Honeycomb implementation disables strict mode...
public class HoneycombStrictPolicy extends VersionedStrictPolicy{
private static final String TAG = "HoneycombStrictPolicy";
public void permitAll () {
Log.i(TAG, "Adjusting StrictMode for authorization...");
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
}The EvernoteOAuthActivity then instantiates the appropriate class depending on the version:
public void onCreate(Bundle savedInstanceState) {
final int androidVersion = Build.VERSION.SDK_INT;
if (androidVersion > Build.VERSION_CODES.GINGERBREAD_MR1) {
VersionedStrictPolicy strictPolicy = new HoneycombStrictPolicy();
strictPolicy.permitAll();
} else {
// we could instantiate the FroyoStrictPolicy, but it is a no-op anyway.
}
...
#4
Posted 10 July 2012 - 04:34 AM
Sorry about the PITA here, we're aware of this and will be resolving it in an upcoming SDK release.
#5
Posted 09 August 2012 - 09:41 AM
I am also having trouble with the same issue.
Can you please tell me exactly when the issue will be resolved.
When do you plan to release the modified version of SDK?
Can you please tell me exactly when the issue will be resolved.
When do you plan to release the modified version of SDK?
Also tagged with one or more of these keywords: android, oauth
Android
Evernote Products →
Evernote →
Problems syncing on Android devicesStarted by NoteLover, Today, 01:47 PM |
|
|
||
Android
Evernote Products →
Evernote →
How to stop tags(action, approved, home, etc) from being created?Started by OrganisedSid, Today, 01:29 AM |
|
|
||
Android
Evernote Products →
Evernote →
[Feature Request] Samsung Multi View SupprtStarted by Mark Levison, Yesterday, 07:22 PM |
|
|
||
Android
Evernote Products →
Skitch →
Try out a Skitch First Launch Experience (and tell us what you think)Started by gbarry, 22 May 2013 |
|
|
||
Android
Evernote Products →
Evernote →
Camera Constantly freezing PhoneStarted by the rugbyman, 21 May 2013 |
|
|
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users












