Open dphans opened 3 years ago
Thanks!
We might, at some point, switch to the new API, but that is absolutely low-priority.
More information on the API is available here as well: https://developer.android.com/training/basics/intents/result
Can you provide new way in java fragment code?
@mhemon did you solve using the new way in java?
you can change original code with this:
public void setListener(final Fragment fragment, final Listener listener, final int requestCodeFilePicker) {
if (fragment != null) {
mFragment = new WeakReference<Fragment>(fragment);
mSelectFileResultLauncher = mFragment.get().registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
onActivityResult(requestCodeFilePicker, result.getResultCode(), result.getData());
});
} else {
mFragment = null;
}
setListener(listener, requestCodeFilePicker);
}
if (mFragment != null && mFragment.get() != null && Build.VERSION.SDK_INT >= 11) {
mSelectFileResultLauncher.launch(i);
// mFragment.get().startActivityForResult(Intent.createChooser(i, getFileUploadPromptLabel()), mRequestCodeFilePicker);
} else if (mActivity != null && mActivity.get() != null) {
mActivity.get().startActivityForResult(Intent.createChooser(i, getFileUploadPromptLabel()), mRequestCodeFilePicker);
}
I know that
onActivityResult
deprecated but still used in next API versions. But I suggest to upgrade to consistent with newer API.Old way (Kotlin)
New way (Kotlin)