| 604 | #ifdef ANDROID |
| 605 | if (strcmp(localhostname, "localhost") == 0 |
| 606 | || localhostname[0] == '\0') |
| 607 | { |
| 608 | hostname = "android"; |
| 609 | bool exception=false; |
| 610 | QAndroidJniEnvironment env; |
| 611 | QAndroidJniObject myID = QAndroidJniObject::fromString("android_id"); |
| 612 | QAndroidJniObject activity = QAndroidJniObject::callStaticObjectMethod |
| 613 | ("org/qtproject/qt5/android/QtNative", "activity", "()Landroid/app/Activity;"); |
| 614 | if (env->ExceptionCheck()) { |
| 615 | env->ExceptionClear(); |
| 616 | exception=true; |
| 617 | } |
| 618 | QAndroidJniObject appctx = activity.callObjectMethod |
| 619 | ("getApplicationContext","()Landroid/content/Context;"); |
| 620 | if (env->ExceptionCheck()) { |
| 621 | env->ExceptionClear(); |
| 622 | exception=true; |
| 623 | } |
| 624 | QAndroidJniObject contentR = appctx.callObjectMethod |
| 625 | ("getContentResolver", "()Landroid/content/ContentResolver;"); |
| 626 | if (env->ExceptionCheck()) { |
| 627 | env->ExceptionClear(); |
| 628 | exception=true; |
| 629 | } |
| 630 | QAndroidJniObject androidId = QAndroidJniObject::callStaticObjectMethod |
| 631 | ("android/provider/Settings$Secure","getString", |
| 632 | "(Landroid/content/ContentResolver;Ljava/lang/String;)Ljava/lang/String;", |
| 633 | contentR.object<jobject>(), |
| 634 | myID.object<jstring>()); |
| 635 | if (env->ExceptionCheck()) { |
| 636 | env->ExceptionClear(); |
| 637 | exception=true; |
| 638 | } |
| 639 | if (exception) |
| 640 | LOG(VB_GENERAL, LOG_ALERT, |
| 641 | "Java exception looking for android id"); |
| 642 | else |
| 643 | hostname = QString("android-%1").arg(androidId.toString()); |
| 644 | } |
| 645 | else |
| 646 | hostname = localhostname; |
| 647 | #else |