问题
I ve developed Android Wear App also SDK is 4.4AW. After finished that applitacion I tested on new android wear SDK that is 5.0.1 Emulator AND motorola360(with 5.0.1) then I recived this errror (Show in the below)
Message Sum:
can't resolve host
Detailed Message:
Unable to resolve host "URL": No address associated with hostname
The App works perfect on 4.4 android wear but failed on 5.0.1 (I used Android studio and there is no Error before execution , Successful Build, Crash on Emulator.)
Im certainly sure that I used internet permision as u can see :
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-feature android:name="android.hardware.type.watch" />
Glade Detail :
apply plugin: 'com.android.application'
android { compileSdkVersion 21 buildToolsVersion "21.1.1"
defaultConfig {
applicationId "com.hakyazilim.onlywear"
minSdkVersion 20
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.support:wearable:1.1.0'
compile 'com.google.android.gms:play-services-wearable:6.5.87'
compile files ('lib/android-async-http-1.4.3.jar')
}
I used "android-async-http-1.4.3.jar" Lib. Following this Code :
String requestURL = "My ASPX page (includes XML)";
asyncHttpClient.get(requestURL, new AsyncHttpResponseHandler() {
@Override
public void onSuccess(String response) {
try {
mTextView.setText(response.toString());
} catch (Exception e) {
e.printStackTrace();
Log.d(">>>>", "Part 1 Load Fail !");
}
}
public void onFailure(Throwable e, String response) {
//"EROR = can't resolve host"
}
});
Best regards
回答1:
Even if Android 5.1.1 support Wi-Fi Feature.
It impossible to directly access the Internet in Android Wear.
You should stick to the Data Layer API , you cannot send http request directly from watch. Fetch internet data from the phone, then transfer it to watch with Data Layer API.
You can see this Does Android Wear support directly access the Internet?
And this document Always-on and Wi-Fi with the latest Android Wear update
来源:https://stackoverflow.com/questions/27712834/android-wear-5-0-cant-resolve-host-http-asyncclient-etc