1. 安装apk:
public static void installApk(Context context, String apkPath) {
File apkfile = new File(apkPath);
if (!apkfile.exists()) {
return;
}
Intent i = new Intent(android.content.Intent.ACTION_VIEW);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setDataAndType(Uri.fromFile(apkfile),
"application/vnd.android.package-archive");
context.startActivity(i);
}
2. 设置ContextMenu标题颜色:
<item name="android:alertDialogTheme">@style/alert_dialog_theme</item>
<style name="alert_dialog_theme" parent="@android:style/Theme.Holo.Light.Dialog">
<item name="android:windowTitleStyle">@style/DialogWindowTitle</item>
</style>
<style name="DialogWindowTitle">
<item name="android:maxLines">1</item>
<item name="android:scrollHorizontally">true</item>
<item name="android:textAppearance">@style/MyTextAppearance</item>
</style>
<style name="MyTextAppearance">
<item name="android:textSize">22sp</item>
<item name="android:textColor">@android:color/holo_red_light</item>
</style>
3. 拷贝文件:
public static void copyFile(File src, File dst) throws IOException {
FileChannel in = new FileInputStream(src).getChannel();
FileChannel out = new FileOutputStream(dst).getChannel();
try {
in.transferTo(0, in.size(), out);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
}
}
4. 检测网络是否可用:
public static boolean networkIsAvailable(Context ctx) {
ConnectivityManager cManager = (ConnectivityManager) ctx
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = cManager.getActiveNetworkInfo();
return info != null && info.isAvailable() && info.isConnected();
}
5. 检测GPS是否打开:
public static boolean gpsIsOpend(Context ctx) {
LocationManager lm = (LocationManager) ctx
.getSystemService(Context.LOCATION_SERVICE);
return lm
.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER);
}