in android programming you need to get usb permission before working with connected device to client device.
i am trying to connect a hack-rf
to android device and use it... but first of all i need to get usb permission and detect that hackrf
.
setup:
1- qt6.3.0
2- ndk 21.3.6528147
3- ui with QML
this is my c++ code to get permission of storage:
bool checkAppPermissions(QString permission)
{
auto result = QtAndroidPrivate::checkPermission(permission).result();
if (result == QtAndroidPrivate::Denied) {
auto result2 = QtAndroidPrivate::requestPermission(permission).result();
qDebug() << permission << result2;
if (result2 == QtAndroidPrivate::Denied)
return false;
else {
return true;
}
}
else {
return true;
}
}
and it's usage:
checkAppPermissions("android.permission.WRITE_EXTERNAL_STORAGE")
but i cannot get usb permisson this way.. its not working.
in AndroidManifest.xml
i put these:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-feature android:name="android.hardware.usb.host"/>
also i think the permission that i had to get is "com.android.example.USB_PERMISSION"
but i dont know how should i Grant or request for that.
this kotlin code works fine... it detects device and gets the permission but i don't know how it is working! or how can i implement it in Qt with cpp.
i also see this answer but i dont know how he uses C++ native side code
or MyActivity.java
could you help me to detect device and grant it's permission at run time.