java.lang.IllegalArgumentException: Can only use lower 16 bits for requestCode
You need to pass a positive number to startActivityForResult
.
androidx requestPermissionLauncher causes java.lang.IllegalArgumentException: Can only use lower 16 bits for requestCode
Add this dependency to fix the issue
implementation 'androidx.fragment:fragment:1.3.4'
Android app crash: java.lang.IllegalArgumentException: Can only use lower 16 bits for requestCode
I found some others questions in the SO with the same problem, seems for some Reason your request code is greater than the maximum you can.
The problem occurs in only few devices may be because the problem is solved in later versions.
This code is from the android.support.v4.app.FragmentActivity
:
/**
* Modifies the standard behavior to allow results to be delivered to fragments.
* This imposes a restriction that requestCode be <= 0xffff.
*/
@Override
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);
}
The code above throw a exception if your problem will occurs, so you can test in any device, just override the method on your activity.
I have seem in a comment that the problem may not occurs if you use an Integer
beside an int
Another workaround may be use some of the APP Compat Libraries.
Link to the post with the answer above.
Can only use lower 16 bits for requestCode (Google play services)
My problem was
GooglePlayServicesUtil.getErrorDialog(resultCode, this, GooglePlayServicesUtil.GOOGLE_PLAY_SERVICES_VERSION_CODE)
Changing that line to
GooglePlayServicesUtil.getErrorDialog(resultCode, this, 9000)
made the button work correctly and open up the settings page.
Related Topics
How to Create Parallelogram Shape Background
How to Run Service Continuously
Check If User Is Authenticated for the First Time in Firebase Google Authentication in Android
Project Has No Default.Properties File! Edit the Project Properties to Set One
How to Pass a File Path Which Is in Assets Folder to File(String Path)
Why Shouldn't I Use System.Out.Println() in Android
Font Size Too Large to Fit in Cache
Multiple Count Down Timers in Recyclerview Flickering When Scrolled
Android: Backspace in Webview/Baseinputconnection
Can't Apply System Screen Brightness Programmatically in Android
Message "Error: Resource Android:Attr/Lstar Not Found"
Android Drawerlayout - No Drawer View Found with Gravity
Fragment Lifecycle: When "Ondestroy" and "Ondestroyview" Are Not Called
How to Play an Mp3 in the Res/Raw Folder of My Android App
Android Opengl Es 2.0 Emulator