Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.IllegalArgumentException: Can only use lower 16 bits for requestCode #2

Closed
Whyser opened this issue Jan 15, 2015 · 6 comments
Labels

Comments

@Whyser
Copy link

Whyser commented Jan 15, 2015

This error is thrown when pressing an upload field (input type='file'). The error is quite straight forward and is probably easily fixed. (Android 4.2 and 5.0.1 tested)

java.lang.IllegalArgumentException: Can only use lower 16 bits for requestCode at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:815) at im.delight.android.webview.AdvancedWebView.openFileInput(AdvancedWebView.java:396) at im.delight.android.webview.AdvancedWebView$2.openFileChooser(AdvancedWebView.java:243) at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:844) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:5039) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) at dalvik.system.NativeStart.main(Native Method)

@ocram ocram added the bug label Jan 15, 2015
@ocram
Copy link
Contributor

ocram commented Jan 15, 2015

Thanks a lot!

This library has only been tested in normal Activity classes so far. But in FragmentActivity, which you used, there is an additional condition:

public void startActivityForResult(Intent intent, int requestCode) {
    if (requestCode != -1 && (requestCode&0xffff0000) != 0) {
        throw new IllegalArgumentException("Can only use lower 16 bits for requestCode");
    }
    super.startActivityForResult(intent, requestCode);
}

So we'll just have to change the hard-coded request code to a lower value.

@Whyser
Copy link
Author

Whyser commented Jan 15, 2015

Nice that you realized that it was related to Fragments (I didn't know that)!

Not sure if this is also related, but fragments "public void onActivityResult (int requestCode, int resultCode, Intent intent)" won't get called, so one has to forward from the parent activity to the correct fragment. (I'm not very experienced Android developer so not sure what the correct/expected behaviour should be in that scenario)

@ocram
Copy link
Contributor

ocram commented Jan 15, 2015

The issue should have been fixed with the following commit now: 90c3937

Can you please try the updated JAR and report if it works?

Regarding your other issue, please make sure that you don't call getActivity().startActivityForResult() but simply startActivityForResult() and then implement onActivityResult() in the Fragment subclass.

@Whyser
Copy link
Author

Whyser commented Jan 15, 2015

It seems to work, thank you!

Regarding my other issue. I'm never calling the startActivityResult(), it's called inside AdvancedWebView.java, in openFileInput(...). Which will only call onActivityResult() in my ActionBarActivity.java (which contain the fragments).

ActionBarActivity.java:

@Override
public void onActivityResult (int requestCode, int resultCode, Intent intent) {
   if(mFragment != null) 
       mFragment.onActivityResult(requestCode, resultCode, intent);
}

@ocram
Copy link
Contributor

ocram commented Jan 15, 2015

You're right, sorry. So onActivityResult will, rightly, never be called inside your Fragment but only in the Activity. Can you please open a new issue for the problem that one has to forward from the Activity to the correct Fragment? Thanks!

@ocram ocram closed this as completed Jan 15, 2015
@anilthummar
Copy link

anilthummar commented Apr 16, 2017

@ocram
Hello Oracam ,

I am working on google fit api integration in my android application , i am getting following error ,
Please help me. Thanks.

i used fitness dependency.

Process: com.alaramdemosample, PID: 16857
java.lang.IllegalArgumentException: Can only use lower 16 bits for requestCode
at android.support.v4.app.BaseFragmentActivityGingerbread.checkForValidRequestCode(BaseFragmentActivityGingerbread.java:88)
at android.support.v4.app.BaseFragmentActivityGingerbread.startIntentSenderForResult(BaseFragmentActivityGingerbread.java:75)
at android.support.v4.app.FragmentActivity.startIntentSenderForResult(FragmentActivity.java:77)
at com.google.android.gms.common.ConnectionResult.startResolutionForResult(Unknown Source)
at com.google.android.gms.common.api.internal.zzw$zzb.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5896)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)

Please help me.

@1170762202 1170762202 mentioned this issue Dec 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants