android 笔记

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);
    }



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值