배경 화면을 만들었지 만 (Android 4.0.3 용) 기본 설정에 문제가 있습니다.PreferenceFragment (라이브 배경 화면)에서 http-get 보내기
서비스 http-get
을 PreferenceFragment
에서 호출하려고하면 응답이 없습니다. 실제로는 전화가 끊긴 것 같습니다.
InputStream stream = null;
StringBuilder fos = null;
try {
URL url = new URL("http://.....");
stream = url.openConnection().getInputStream();
InputStreamReader reader = new InputStreamReader(stream);
fos = new StringBuilder();
int next = -1;
while ((next = reader.read()) != -1) {
fos.append((char)next);
}
} catch (Exception e) {
// ...
} finally {
// ...
}
또는 libgdx
같은 외부 프레임 워크 : 내가 좋아하는 전화와 시도
HttpRequest httpRequest = new HttpRequest(HttpMethods.GET);
httpRequest.setUrl("http://.....");
NetJavaImpl net = new NetJavaImpl();
net.sendHttpRequest(httpRequest, this);
는데 아무런 동작도하지 않습니다. 장치에 대한 추적이나 확률 예외가 없습니다.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="it.mytest.live"
android:installLocation="preferExternal"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.SET_WALLPAPER" />
<uses-feature
android:name="android.software.live_wallpaper"
android:required="true" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".MyWallpaperSettings"
android:exported="true"
android:hardwareAccelerated="false"
android:label="MyWallpaperSettings"
android:permission="android.permission.INTERNET" />
<service
android:name=".MyWallpaper"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:permission="android.permission.BIND_WALLPAPER" >
<intent-filter>
<action android:name="android.service.wallpaper.WallpaperService" />
</intent-filter>
<meta-data
android:name="android.service.wallpaper"
android:resource="@xml/livewallpaper"
android:value="true" />
</service>
</application>
</manifest>
당신이 어떤 생각을 가지고 있습니까 :
는이 같은 매니페스트가? 나는 미친 :(* 편집을하려고 해요 : 해결, 감사합니다! *
private class SendAsyncTask extends AsyncTask<String, String, String>
{
protected String doInBackground(String... status)
{
String result = "";
try
{
String url = "my magic http-get";
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(new HttpGet(url));
if(response != null && response.getEntity() != null)
{
InputStream stream = response.getEntity().getContent();
try
{
// parse an XML with libgdx ...
XmlReader xmlReader = new XmlReader();
Element root = xmlReader.parse(stream);
Array<Element> childs = root.getChildrenByNameRecursively("mykids");
for (Element child: childs)
{
Element myelement = child.getChildByName("name");
//do something...
}
}
catch (Exception e)
{
//
}
finally
{
try
{
stream.close();
}
catch (Exception e)
{
//
}
}
}
}
catch (Exception e)
{
//
}
return result;
}
protected void onPostExecute(String result)
{
super.onPostExecute(result);
}
}
당신이 UI 스레드에서이 작업을 수행하려고 : 당신이 모든 예외를 삼킨 것 같다? –