文章标签 ‘Android’


2017年6月19日 没有评论




<activity android:name=”.MainActivity” android:launchMode=”standard” />


1. standard


2. singleTop

如果在任务的栈顶正好存在该Activity的实例, 就重用该实例,否者就会创建新的实例并放入栈顶(即使栈中已经存在该Activity实例,只要不在栈顶,都会创建实例)。

3. singleTask


4. singleInstance


大家遇到一个应用的Activity供多种方式调用启动的情况,多个调用希望只有一个Activity的实例存在,这就需要Activity的onNewIntent(Intent intent)方法了。只要在Activity中加入自己的onNewIntent(intent)的实现加上Manifest中对Activity设置lanuchMode=“singleTask”就可以。

onNewIntent()非常好用,Activity第一启动的时候执行onCreate()—->onStart()—->onResume()等后续生命周期函数,也就时说第一次启动Activity并不会执行到onNewIntent(). 而后面如果再有想启动Activity的时候,那就是执行onNewIntent()—->onResart()——>onStart()—–>onResume().  如果android系统由于内存不足把已存在Activity释放掉了,那么再次调用的时候会重新启动Activity即执行onCreate()—->onStart()—->onResume()等。

当调用到onNewIntent(intent)的时候,需要在onNewIntent() 中使用setIntent(intent)赋值给Activity的Intent.否则,后续的getIntent()都是得到老的Intent。

分类: Android 标签: ,


2017年5月12日 没有评论


* Handles secret codes to launch arbitrary activities in the form of *#*#<code>#*#*.
* If a secret code is encountered an Intent is started with the android_secret_code://<code>
* URI.
* @param context the context to use
* @param input the text to check for a secret code in
* @return true if a secret code was encountered
static boolean handleSecretCode(Context context, String input) {
// Secret codes are in the form *#*#<code>#*#*
int len = input.length();
if (len > 8 && input.startsWith("*#*#") && input.endsWith("#*#*")) {
final Intent intent = new Intent(SECRET_CODE_ACTION,
Uri.parse("android_secret_code://" + input.substring(4, len - 4)));
return true;

return false;

分类: Android 标签:


2017年5月3日 没有评论

adb root
adb remount

adb push services.jar /system/framework
adb push framework.jar /system/framework
adb push framework-res.apk /system/framework

adb push arm/boot.oat /system/framework/arm
adb push arm/boot.art /system/framework/arm
adb push arm/boot-framework.oat /system/framework/arm
adb push arm/boot-framework.art /system/framework/arm

adb push arm64/boot.oat /system/framework/arm64
adb push arm64/boot.art /system/framework/arm64
adb push arm64/boot-framework.oat /system/framework/arm64
adb push arm64/boot-framework.art /system/framework/arm64

adb reboot

echo off
echo YES | copy \\ip\&lt;branch1&gt;\out\target\product\&lt;product&gt;\system\priv-app\SystemUI\SystemUI.apk .
md5sum SystemUI.apk
adb push SystemUI.apk /system/priv-app/SystemUI/SystemUI.apk
adb shell am force-stop com.android.systemui
echo on

mmm core/res &amp;&amp; mm &amp;&amp; mmm services &amp;&amp; mm

mmm -B core/res &amp;&amp; mm -B &amp;&amp; mmm -B services &amp;&amp; mm -B

分类: Android 标签: ,

How to Download/Compile Specific Parts of a ROM

2017年5月2日 没有评论

How to Download/Compile Specific Parts of a ROM

This is a tutorial about how to download and compile specific parts in AOSP based roms (such as CyanogenMod, AOKP, SlimRom etc)
It’s mainly dedicated for the people who want to get more familiar with the AOSP build environment, and would like to manipulate it’s behavior to complete specific tasks.

Downloading ROM sources is done with the tool “repo”, this is the most awesome downloader in existence. Not only it looks very cool, it also reaches top speed at all times. But it’s only for linux (which is good, since when you are busy with aosp roms, you should be on linux!)
Why is it awesome? Since you decide yourself how many jobs (aka connections) you make with the server. This means you always will get top speed, there is probably no faster download method available on the Internet (except for speedtests, but they don’t count). Next to the downloading of specific parts it’s of course also handy to know how to actually compile them.


1. Download
2. Compile

3. Automate (optional)


Chapter 1. Download:
The easiest way of fetching for example a batch of AOSP apps is like this:

1. Choose the desired tag you want to use, in the example I will use android-4.2.2_r1
2. Now make a dir somewhere:

3. Download repo when not installed yet:

4. Enter the line that will download the initial manifest.

for AOSP:

Enter your name and email address and wait until it completes

for CM:

5. Go in the hidden “.repo” dir and change the manifest

If you don’t have decent text editor such as “gedit”, install it! “sudo apt-get install gedit”


For example when you only want to download the apps, just remove all lines that are not app related. simple as that

When done, save it and go a dir back in the terminal

6. Download the packages

(With a 60mb/s connection you already get the max download speed with ” -j4 ” which is the default of github)

The packages will be download as quickly as possible to your harddrive now.


Chapter 2. Compile:
To compile the obtained packages separately you will need a AOSP environment (or CM/AOKP etc). When you have a succesfull environment which is able to compile for your device you may enter:

now you’re theoretically ready to compile
to compile an app on the easiest way:

where “Appname” is the name of the folder placed in packages/apps/..
This also counts for “SystemUI” which is not in that folder

And the -j param again stands for the number of jobs, remember that this is compiling and not downloading, so the “standard rule” with this is, number of cores of your CPU + 1.
Which makes a regular quad core (-j5) but makes a i7 CPU with Hyper threading (-j9). When using -j16 for example on a regular quad core it could happen that your CPU will be overloaded so much that your mouse will lag all over the place.
(Linux forces the cpu to perform higher then it actually should, resulting in unwanted situations)

When having trouble, when it stops or just nags about some missing symbols or something like that.
You should try using the “-k” param, this tells the make command to keep going when a non-critical error occurs.

When having issues with the local module tags, you should enter this:

To compile other parts you also need to enter the folder name, here are some examples from /frameworks/base

or more examples:


Chapter 3. Automate

If you regularly want to compile specific ROM parts you can make a shell script that automates the process for you.

Make a new document with some name, for example “buildessentials”, open the file with your favorite text editor (gedit is recommended)
and place this line at the very top of your document:

This indicates that this file should call /bin/bash, which is the shell interpreter.

Under this line you should place all the single commands that you want to be executed when running the script. For example:

So your total output would be:

Now you should change the permissions of the files, which need to be RWX-RX-RX, which is 755.
This can be done by entering this in the shell:

Now you can run the script by entering:

分类: Android 标签: ,


2017年5月1日 没有评论
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
#AOSP download command
repo init -u https://android.googlesource.com/platform/manifest
repo init -u https://android.googlesource.com/platform/manifest -b android-7.1.2_r6

#lineageos download command
cd ~/android/lineage
repo init -u https://github.com/LineageOS/android.git -b cm-14.1
repo sync -c -d -j2 --no-tags
分类: Android 标签: , ,

Android 刷机常用命令

2017年4月29日 没有评论

Android 刷机常用命令


ROM Flashing
  • 1、下载合适的ROM
  • 2、拷贝zip格式的ROM文件,到SD卡
  • 3、重启并进入recovery模式
  • 4、备份手机,清除数据
  • 5、菜单选择刷机
  • 6、选择ROM文件
  • 7、确定
  • 8、成功后重启
RUU Flashing
  • 1、Android设备连接电脑。
  • 2、下载ROM升级工具(ROM Upgrade Utilities (RUUs))
  • 3、手机通过USB连接电脑,运行RUU
  • 4、按照RUU说明刷机
  • 5、正在刷机,除非出错
Android Flashing Guide (with fastboot)
  • 需要未锁定的bootloader或开发模式的bootloader
Unlocking your bootloader(解锁bootloader)
  • Nexus One (cannot be relocked).
    • fastboot oem unlock
    • 接受/拒绝屏幕警告
  • Nexus S (can be unlocked and relocked)
    • fastboot oem unlock
    • 接受/拒绝屏幕警告
    • fastboot oem lock  //重新锁定bootloader
ROM Flashing
  • 1、下载ROM,记录ROM在PC上的路径
  • 2、重启手机进入fastboot mode,通过下面两种方法之一
    • 1、adb reboot bootloader (需要USB调试开关打开).
    • 2、关机长按音量加和电源按钮
  • 3、清除手机数据
    • fastboot -w
  • 4、升级到ROM
    • fastboot update </path/to/your/RomFile.zip>
  • 5、你的手机将刷机并自动重启到新的ROM
ROM update without SDcard


  • 1、进入手机Recovery模式
  • 2、adb shell
  • 3、mount data
  • 4、Ctrl+C
  • 5、adb push </path/to/your/RomFile.zip> /data/
  • 6、等待ROM包上传完成,使用命令adb reboot-bootloader重新进入recovery
  • 7、mount data
  • 8、mount /data /sdcard (挂载data文件夹到sdcard挂载点)
  • 9、定位ROM的zip文件
  • 10、确认刷机
  • 11、刷机无错误,重启系统
  • 12、删除data下的ROM刷机包(在ROOT权限下,使用文件浏览器删除,或者命令adb shell rm </path/to/your/RomFile.zip>删除)



  • 使用ROM Manager or GooManager
  • 使用Fastboot
  • 使用flash_image
Install ClockworkMod Recovery with ROM Manager:


Install TWRP Recovery with GooManager:


Install any Custom Recovery with Fastboot:
  • 1、下载recovery镜像
  • 2、USB连接Android设备
  • 3、进入fastboot模式
    • adb reboot bootloader
  • 4、flash
    • fastboot flash recovery </path/to/your/recovery.img>
  • 5、等待进度完成,重启手机
    • fastboot reboot
Install any Custom Recovery with flash_image:
  • 1、下载flash image,解压到C盘根目录
  • 2、下载recovery镜像
  • 3、开启手机开发者选项:Menu > Settings > Applications > Development
  • 4、USB连接Android设备
  • 5、命令行敲命令:
    adb push c:\flash_image /sdcard/
    adb push c:\recovery.img /sdcard/
    adb shell
    mount -o remount, rw /system
    cp /sdcard/flash_image /system/bin
    cd /system/bin
    chmod 777 flash_image
    flash_image recovery /sdcard/recovery.img
  • 6、等待进度完成,重启手机
分类: Android 标签: , ,


2017年3月22日 没有评论

虽然大部分Android bootloader是闭源的,但是大部分基于高通芯片的ARM设备bootloader是基于Little Kernel(LK) bootloader修改得到的。而LK bootloader是开源的。


分类: Android, 未分类 标签: ,


2017年3月22日 没有评论

传统沙箱极大依赖于Linux默认的自主访问控制(DAC);SELinux(安全加强Linux)的强制访问控制(mandatory access control,MAC)可以通过以下方法尝试克服Linux DAC的局限:执行全局的细粒度安全策略,并要求只有系统管理员才能修改这些策略。



分类: Android, 未分类 标签: ,


2017年3月22日 没有评论

NFC简介:Near Field Communication,NFC是近距离(10cm或更少)的设备之间通过建立无线电通信交换数据的技术。NFC是建立在一系列标准之上,这些标准定义了无线电通信频率、传输协议和数据交换格式。NFC建立在无线电射频识别(RFID)技术的基础上,使用13.56MHz的工作频率,并支持多个数据传输速率。NFC设备能够以三种不同的模式进行工作:读写(R/W)、点对点(P2P)和卡模拟(CE)。

分类: Android, 未分类 标签: ,


2017年3月22日 没有评论

恢复系统(recovery):recovery系统是一个小型的基于linux的操作系统,其中包括一个内核,包含有各种底层工具的RAM磁盘,和一个通过设备硬件按键操作的小型UI。recovery被用来应用系统更新。而更新一般是以OTA(Over-The-Air)更新包的形式来发布,其中包含新版本的系统文件(或补丁)和安装此更新的脚本文件。OTA文件一般都是被设备制造商的私钥签名过的。recovery保存在一个特定分区中, 阅读全文…

分类: Android, 未分类 标签: ,