How add information in user-agent ? QML Web View Android



  • i see example minibrowser for android, but me need add information imei phone

    this default user-agent: "Mozilla/5.0 (Linux; Android 5.0.2; Redmi Note 2 Build/LRX22G; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/63.0.3239.111 Mobile Safari/537.36"

    need "Mozilla/5.0 (Linux; Android 5.0.2; Redmi Note 2 Build/LRX22G; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/63.0.3239.111 Mobile Safari/537.36 IMEI(----------------)"

    How do it?

    this function get IMEI
    QString InfoDevice::getDeviceImei()
    {
            QAndroidJniEnvironment env;
    
            jclass contextClass = env->FindClass("android/content/Context");
            jfieldID fieldId = env->GetStaticFieldID(contextClass, "TELEPHONY_SERVICE", "Ljava/lang/String;");
            jstring telephonyManagerType = (jstring) env->GetStaticObjectField(contextClass, fieldId);
    
            jclass telephonyManagerClass = env->FindClass("android/telephony/TelephonyManager");
            jmethodID methodId = env->GetMethodID(contextClass, "getSystemService", "(Ljava/lang/String;)Ljava/lang/Object;");
    
           QAndroidJniObject qtActivityObj = QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative",  "activity", "()Landroid/app/Activity;");
            jobject telephonyManager = env->CallObjectMethod(qtActivityObj.object<jobject>(), methodId, telephonyManagerType);
    
            methodId = env->GetMethodID(telephonyManagerClass, "getDeviceId", "()Ljava/lang/String;");
            jstring jstr = (jstring) env->CallObjectMethod(telephonyManager, methodId);
    
            jsize len = env->GetStringUTFLength(jstr);
            char* buf_devid = new char[32];
            env->GetStringUTFRegion(jstr, 0, len, buf_devid);
            QString imei(buf_devid);
            delete buf_devid;
            return imei;
    }
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.