android常用接口
常见的一些调用接口 更多阅读全文后star,实时更、更新收集到的接口
需要交流,联系微信:code_gg_boy 更多精彩,时时关注微信公众号code_gg_home
public int convertDipOrPx(int dip) { float scale = MarketApplication.getMarketApplicationContext()
.getResources().getDisplayMetrics().density; return (int) (dip * scale + 0.5f * (dip >= 0 ? 1 : -1));
}
getWindowManager()
.addView(
overlay, new WindowManager.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_APPLICATION,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
PixelFormat.TRANSLUCENT));
try {
Field f = AbsListView.class.getDeclaredField("mFastScroller");
f.setAccessible(true);
Object o = f.get(listView);
f = f.getType().getDeclaredField("mThumbDrawable");
f.setAccessible(true);
Drawable drawable = (Drawable) f.get(o);
drawable = getResources().getDrawable(R.drawable.ic_launcher);
f.set(o, drawable);
Toast.makeText(this, f.getType().getName(), 1000).show();
} catch (Exception e) { throw new RuntimeException(e);
}
=网络=
/**
* 网络是否可用
*
* @param context
* @return
*/
public static boolean isNetworkAvailable(Context context) {
ConnectivityManager mgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo[] info = mgr.getAllNetworkInfo(); if (info != null) { for (int i = 0; i < info.length; i++) { if (info[i].getState() == NetworkInfo.State.CONNECTED) { return true;
}
}
} return false;
}
方法二:
/*
* 判断网络连接是否已开 2012-08-20true 已打开 false 未打开
*/
public static boolean isConn(Context context) { boolean bisConnFlag = false;
ConnectivityManager conManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo network = conManager.getActiveNetworkInfo(); if (network != null) {
bisConnFlag = conManager.getActiveNetworkInfo().isAvailable();
} return bisConnFlag;
}
public static boolean isWifiActive(Context icontext) {
Context context = icontext.getApplicationContext();
ConnectivityManager connectivity = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo[] info; if (connectivity != null) {
info = connectivity.getAllNetworkInfo(); if (info != null) { for (int i = 0; i < info.length; i++) { if (info[i].getTypeName().equals("WIFI")
&& info[i].isConnected()) { return true;
}
}
}
} return false;
}
/**
* 网络方式检查
*/
private static int netCheck(Context context) {
ConnectivityManager conMan = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
State mobile = conMan.getNetworkInfo(ConnectivityManager.TYPE_MOBILE)
.getState();
State wifi = conMan.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
.getState(); if (wifi.equals(State.CONNECTED)) { return DO_WIFI;
} else if (mobile.equals(State.CONNECTED)) { return DO_3G;
} else { return NO_CONNECTION;
}
}
public String getReallyFileName(String url) {
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectDiskReads().detectDiskWrites().detectNetwork() // 这里可以替换为detectAll()
// 就包括了磁盘读写和网络I/O
.penaltyLog() // 打印logcat,当然也可以定位到dropbox,通过文件保存相应的log
.build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectLeakedSqlLiteObjects() // 探测SQLite数据库操作
.penaltyLog() // 打印logcat
.penaltyDeath().build());
String filename = "";
URL myURL;
HttpURLConnection conn = null; if (url == null || url.length() < 1) { return null;
} try {
myURL = new URL(url);
conn = (HttpURLConnection) myURL.openConnection();
conn.connect();
conn.getResponseCode();
URL absUrl = conn.getURL();// 获得真实Url
// 打印输出服务器Header信息
// Map<String, List<String>> map = conn.getHeaderFields();
// for (String str : map.keySet()) {
// if (str != null) {
// Log.e("H3c", str + map.get(str));
// }
// }
filename = conn.getHeaderField("Content-Disposition");// 通过Content-Disposition获取文件名,这点跟服务器有关,需要灵活变通
if (filename == null || filename.length() < 1) {
filename = URLDecoder.decode(absUrl.getFile(), "UTF-8");
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally { if (conn != null) {
conn.disconnect();
conn = null;
}
} return filename;
}