if (true) { new Thread() { private StringBuilder mBuilder; @Override public void run() { super.run(); try { URL url = new URL("http://ic.snssdk.com/2/article/v25/stream/?category=news_tech&count=20&bd_latitude=4.9E-324&bd_longitude=4.9E-324&bd_loc_time=1457695555&loc_mode=5&lac=4527&cid=28883&iid=3835029558&device_id=12211880440&ac=wifi&channel=baidu&aid=13&app_name=news_article&version_code=460&device_platform=android&device_type=iToolsAVM&os_api=1"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setConnectTimeout(5000); conn.setRequestMethod("GET"); if (conn.getResponseCode() == 200) { InputStream input = conn.getInputStream(); StringBuffer sb = new StringBuffer(); BufferedReader buffered = new BufferedReader(new InputStreamReader(input)); String line = null; while ((line = buffered.readLine()) != null) { sb.append(line); } Log.i("zzzz", sb.toString()); // Message msg = Message.obtain(handler, 0, sb.toString()); // msg.sendToTarget(); Message msg = new Message(); msg.what = 0; msg.obj = sb.toString(); handler.sendMessage(msg); } } catch (Exception e) { e.printStackTrace(); } // Message msg = new Message(); // msg.what=0; // msg.obj=mBuilder.toString(); // handler.sendMessage(msg); } }.start(); } else { final AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity()); dialog.setTitle("是否通过移动数据访问?"); dialog.setNegativeButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { dialog.create().dismiss(); } }); dialog.setPositiveButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { Intent intent = null; if (android.os.Build.VERSION.SDK_INT > 10) { intent = new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS); } else { intent = new Intent(); intent.setClassName("com.android.settings", "com.android.settings.WirelessSettings"); intent.setAction("android.intent.action.VIEW"); } startActivity(intent); } }); dialog.create().show(); } } //判断WIFI连接是否可用; private boolean Connected(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if(info.isConnected()){ return true; } return false; }
wifi判断
最新推荐文章于 2021-06-03 16:34:51 发布