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