Code is working fine for Android 8 and 9, this issue only in Android 10. We can run in Android 10 by using the command adb shell settings put global hidden_api_policy
adb shell settings put global hidden_api_policy