Yifei Kong

Apr 04, 2018

Android SharedPreference

用来在应用中存储键值对配置

context.getSharedPreferences("prefName", Context.MODE_PRIVATE) get SharedPreferecnes instance sharedPref.getXXX("keyName", defaultValue) get value from SharedPreferences sharedPref.edit() get editor(SharedPreference.Editor) editor.putXXX("key-name", value) put value editor.commit() commit the changes

Apr 04, 2018

Android 开发的一些 tips

Prefer Maven dependency resolution instead of importing jar files. If you explicitly include jar files in your project, they will be of some specific frozen version, such as 2.1.1. Downloading jars and handling updates is cumbersome, this is a problem that Maven solves properly, and is also encouraged …

Apr 04, 2018

Android 连接 WiFi

https://stackoverflow.com/questions/4249911/android-how-to-create-eap-wifi-configuration-programmatically

redirects to

https://stackoverflow.com/questions/4374862/how-to-programmatically-create-and-read-wep-eap-wifi-configurations-in-android

https://stackoverflow.com/questions/19170260/how-to-connect-to-wpa-eap-wifi-on-android-with-4-3-api

Android 6.0 changes

https://developer.android.com/about/versions/marshmallow/android-6.0-changes.html#behavior-network

working methods

https://stackoverflow.com/questions/12486441/how-can-i-set-proxysettings-and-proxyproperties-on-android-wi-fi-connection-usin

get real ip https://stackoverflow.com/questions …

Apr 04, 2018

Maven Basics

From: http://tutorials.jenkov.com/maven/maven-tutorial.html

Introduction

Maven is built around the pom.xml file. In Maven, how to build your project is predefined in the Maven Build Life Cycles, Phases and Goals. The POM file describes what to build, but most often not how to build it …

Apr 04, 2018

使用 Gson 解析 json 文档

解析 json 有两种流派:

  1. event-driven json parse: iterate the document, not loading all into memory
  2. document-based json parse: load the full document into memory once for all.

在 Python 中可以很容易的解析json文件,Python 中的 json.loads 是 document-based。而在 java 中可以使用 event-driven的。个人感觉这种 event-driven 的解析方式是多此一举,json本来定位就是小型的数据传输和配置存储,如果生成了一个很大的 json,应该考虑换用xml了。

在 Java 中需要生成和 JSON …

Feb 24, 2018

安卓证书与代理自动配置

Go to Settings > Security > Install from storage.

install programatically can be achived by from command line, by moving certs to

replacing bks file solely is useless, it has to be combined with the password

https://github.com/danzeeeman/meerkat-decompiled/blob/master/io/fabric/sdk/android/services/network/PinningInfoProvider.java

set …

Nov 15, 2017

安卓开发中的Context

在安卓当中,Context几乎是无处不在的,每一个Activity是一个Context,每一个Service也是一个Context。

但是如果你新起了一个线程的话,你需要显式地把Context传递进去。

比如下面的例子:

public class DumpLocationLog extends Thread {
    LocationManager lm;
    LocationHelper loc;
    public DumpLocationLog(Context context) {
        loc = new LocationHelper();
        lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    }
    public void run() {
        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000L, 500.0f, loc);
    }
}

然后使用这个线程的时候,把this,也就是一个context的实例传递进去

new DumpLocationLog(this);

if you are in …

Nov 15, 2017

为安卓编译64位的dropbear

如何使用dropbear

这里主要是需要在安卓上生成 host key,以及把自己的公钥传到安卓上

dropbearkey -t rsa -f /data/local/dropbear_host_key # 在安卓上生成key
adb push ~/.ssh/id_rsa.pub /data/local/authorized_keys # 在宿主机把自己的密钥传过去
dropbear -F -E -r /data/local/dropbear_host_key -A -N root -C jk -R /data/local/authorized_keys # 按照给定的key启动dropbear
dropbear -P /data/local/dropbear.pid -r /data/local/dropbear_host_key -A …

Nov 15, 2017

安卓反编译的一些笔记

工具

apk studio

如何 sign:https://www.nevermoe.com/?p=373

smali code tutorial: https://forum.xda-developers.com/showthread.php?t=2193735

一篇很好的pdf的文档,利用smali code:http://www.security-assessment.com/files/documents/whitepapers/Bypassing%20SSL%20Pinning%20on%20Android%20via%20Reverse%20Engineering.pdf

安卓中 pinning 的原理

使用自己的keystore实例化 TrustManagerFactory

关键语句

InputStream in = resources …

Nov 15, 2017

安卓的 AsyncTask

asynchronusally run task without explicitly creating thread.

Usage

doInBackground(Params...)
onProgressUpdate(Progress...)
onPostExecute(Result)

Here is an example of subclassing:

 private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> {
     protected Long doInBackground(URL... urls) {
         int count = urls.length;
         long totalSize = 0;
         for (int i = 0; i < count; i++) {
             totalSize += Downloader.downloadFile …
Next → Page 1 of 3