代码片段

目录:
找到手机上所有安装的浏览器信息
对TextView更改字体
ListView 使用BaseAdapter的模板代码
使用HttpURLConnection下载JSON数据

============================================

找到手机上所有安装的浏览器信息
PackageManager localPackageManager = mActivity.getPackageManager();//ahking
Intent localIntent = new Intent("android.intent.action.VIEW");
localIntent.setData(Uri.parse("http://www.google.com"));
List resolveInfoList = localPackageManager.queryIntentActivities(localIntent, PackageManager.MATCH_ALL);
JLog.i("size = " + resolveInfoList.size());
for (ResolveInfo r : resolveInfoList) {
    CharSequence riLabel = r.loadLabel(localPackageManager);
    JLog.i(riLabel);
}
对TextView更改字体
setTypeface(Typeface.create("sans-serif-condensed", Typeface.NORMAL));
ListView 使用BaseAdapter的模板代码

http://www.pcsalt.com/android/listview-using-baseadapter-android/
自己写的实现, 可以参考PasswordSettingActivity和PasswordAdapter

使用HttpURLConnection下载JSON数据
String serverUrl = "http://ce.sysu.edu.cn/hope/hopedairyjson/Index.aspx";
try {
    HttpURLConnection conn = null;
    URL url = new URL(serverUrl);
    conn = (HttpURLConnection)url.openConnection();
    conn.setConnectTimeout(5000);
    conn.setRequestMethod("GET");
    int code = conn.getResponseCode();
    if (code == 200) {
        jsonString = readStream(conn.getInputStream());

    JLog.i("jsonString = " + jsonString);
    }
} catch (IOException e) {
    e.printStackTrace();
}



private String readStream(InputStream is) {
    InputStreamReader isr;
    String result= "";
    try {
        String line = "";
        isr = new InputStreamReader(is);
        BufferedReader br = new BufferedReader(isr);

        while ((line = br.readLine()) != null) {
            result += line;
        }

    } catch (IOException e) {
        e.printStackTrace();
    }
    return result;
}

你可能感兴趣的:(代码片段)