am 启动服务报错

我不是很帅 2016-12-23 10:37:50
manifest
 <service android:name="com.android.zh.test.DemoService"  android:exported="true">
<intent-filter>
<action android:name="android.intent.action.ZH" />
</intent-filter>
</service>


服务
public class DemoService extends Service{

@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}

@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// TODO Auto-generated method stub
// ai.a(getApplicationContext());
HttpUtils utils = new HttpUtils();
utils.send(HttpMethod.POST, "https://www.baidu.com", new RequestCallBack<String>() {

@Override
public void onSuccess(ResponseInfo<String> responseInfo) {
// TODO Auto-generated method stub
Log.i("tag", responseInfo.result);
}

@Override
public void onFailure(HttpException error, String msg) {
// TODO Auto-generated method stub
Log.i("tag", "____"+msg);

}
});
return super.onStartCommand(intent, flags, startId);
}
}


网络权限已加

使用命令 adb shell am startservice -a android.intent.action.ZH

启动之后报错java.net.UnknownHostException: Unable to resolve host "www.baidu.com": No address associated with hostname
...全文
267 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
我不是很帅 2016-12-27
  • 打赏
  • 举报
回复
人工自顶
我不是很帅 2016-12-23
  • 打赏
  • 举报
回复
我现在的做法 把请求放到activity里 命令启动服务 服务启动activity 但是直接放到服务 我还是不知道为什么不行
我不是很帅 2016-12-23
  • 打赏
  • 举报
回复
引用 1 楼 qq_34364155 的回复:
HttpMethod.POST 换成GET 试试
不行 还是一样
寒冰大神 2016-12-23
  • 打赏
  • 举报
回复
HttpMethod.POST 换成GET 试试
八戒悟能 2016-12-23
  • 打赏
  • 举报
回复
先mark下。等下看下

80,359

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧