Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> android開發中積累的小知識

android開發中積累的小知識

編輯:關於Android編程

一:開機logo ,在根路徑7627a_splash下把圖片放入,運行splash.sh文件
然後再把splash.txt中的值復制粘帖在bootable/bootloader/lk/target/項目名/include/target/的splash.h文件中
再make aboot

把out/target/product/項目名/下面(emmc_appsboot.mbn,emmc_appsboothd.mbn)這個是針對與emmc,或者是(appsboot.mbn,appsboothd.mbn)這個是針對nand。把這2個文件考出來,在window下用qts燒寫進去。


二:修改開關機動畫
把制作好的bootanimation.zip和shutdownanimation.zip放到 /system/core/rootdir/項目名/。

可以直接push到機器的system/media下面,重啟就可以看到效果


三:判斷項目名
import android.os.SystemProperties;
private boolean mIsA100 = "msm7627a_v12_a100".equals(SystemProperties.get("ro.product.name"));


if("1".equals(SystemProperties.get("persist.sys.emmcsdcard.enabled")))這是把內存設在為內部存儲

在cpp文件中
#include
char value[PROPERTY_VALUE_MAX];
property_get("sys.secpolicy.camera.disabled", value, "0");獲取值


四:查看某個人的所以提交 git log --author="xxxx"

五:進入fastboot模式,可以命令adb reboot-bootloader,#*20110606#打開測試開關

六:添加USB,在/etc/udev/rules.d下

七:
Intent.ACTION_USER_PRESENT這個為解鎖的廣播
KeyguardManager mKeyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);

if (mKeyguardManager.inKeyguardRestrictedInputMode()) {
為鎖屏狀態
}
八:檢測耳機是否插入 public boolean checkHeadSet() {
AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
return audio.isWiredHeadsetOn();
}

Intent.ACTION_HEADSET_PLUG這個為監聽耳機的插拔

九:給應用分配最小的內存
VMRuntime.getRuntime()
.setTargetHeapUtilization(TARGET_HEAP_UTILIZATION);
VMRuntime.getRuntime().setMinimumHeapSize(CWJ_HEAP_SIZE);
private final static float TARGET_HEAP_UTILIZATION = 0.75f;

private final static int CWJ_HEAP_SIZE = 6 * 1024 * 1024;

十:monkey測試的命令
adb shell monkey -v -p com.android.XXX --pct-nav 0 --pct-majornav 0 --pct-anyevent 0 --ignore-security-exceptions --throttle 100 -v 50000

十一:不通過數據庫直接獲取視頻第一幀
public static Bitmap createVideoThumbnail(Context context, Uri uri) {
Bitmap bitmap = null;
String className = "android.media.MediaMetadataRetriever";
Object objectMediaMetadataRetriever = null;
Method release = null;

try {

objectMediaMetadataRetriever = Class.forName(className).newInstance();
Method setModeMethod = Class.forName(className).getMethod("setMode", int.class);
setModeMethod.invoke(objectMediaMetadataRetriever,
MediaMetadataRetriever.MODE_CAPTURE_FRAME_ONLY);

Method setDataSourceMethod = Class.forName(className).getMethod(
"setDataSource", Context.class, Uri.class);
setDataSourceMethod.invoke(objectMediaMetadataRetriever, context,uri);

Method captureFrameMethod = Class.forName(className).getMethod("captureFrame");
release = Class.forName(className).getMethod("release");

bitmap = (Bitmap) captureFrameMethod
.invoke(objectMediaMetadataRetriever);

} catch (Exception e) {
e.printStackTrace();
} finally {try {
if (release != null) {
release.invoke(objectMediaMetadataRetriever);
}
} catch (Exception e) {

// Ignore failures while cleaning up.
e.printStackTrace();
}
}
return bitmap;
}

十二:8x25系列camera配置
後攝 500 萬 ov5640 ov5647 s5k4e1已經添加
前攝 30萬 gc0339 ov9726 ov7692 也已添加
kernel/arch/arm/configs/msm8x25_d8_eg530-perf_defconfig

十三:判斷music是否在播放
AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
if(audioManager.isMusicActive())
{
......}


十四:殺死本進程

android.os.Process.killProcess(android.os.Process.myPid());

十五:抓取log
1:帶有時間的log: adb logcat -v time >>log.txt
2:把log保存在手機裡面,這時候可以在後台運行
adb shell; logcat -vtime >data/log.txt &

十六:選擇編譯,例如在Android.mk裡面,如果msm8x25q_d10_j320c項目,則編譯d10_j320c/AndroidManifest.xml這個文件。
ifneq (, $(filter msm8x25q_d10_j320c, $(TARGET_PRODUCT)))
LOCAL_MANIFEST_FILE := d10_j320c/AndroidManifest.xml
endif

十七:外部U盤無法掛載
在DOS中鍵入, chkdsk F: /f

十八:隱藏輸入法
1:隱藏其他應用打開的輸入法
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);

2:隱藏本應用打開的輸入法
InputMethodManager inputMethodManager = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);

inputMethodManager.hideSoftInputFromWindow(OpeListActivity.this.getCurrentFocus().getWindowToken(),InputMethodManager.HIDE_NOT_ALWAYS);

十九:camera的翻轉
有兩個地方可以改,但是這個要是情況而定,改其中一個
1:在CameraService.cpp中的sendCommand中

if (cmd == CAMERA_CMD_SET_DISPLAY_ORIENTATION) {
// Mirror the preview if the camera is front-facing.
bool isqqpimsecure = false;
if (mCameraFacing == CAMERA_FACING_FRONT) {
int fd;
char buf[1024] = {0};



snprintf(buf,1024,"/proc/%d/cmdline",getCallingPid());
if ((fd = open(buf,O_RDONLY)) != -1) {
if((read(fd, buf, 1023)) != -1) {
ALOGE("sendCommand pid=%d, pname=%s", getCallingPid(), buf);
}
close(fd);

}

if (strcmp(buf, "com.tencent.qqpimsecure") == 0 || strcmp(buf, "com.tencent.mobileqq") == 0 || strcmp(buf, "com.tencent.mobileqq:video") == 0) {
ALOGE("sendCommand pid=%d, pname=%s modifty 180 for com.tencent.qqpimsecure", getCallingPid(), buf);
isqqpimsecure = true;
}
}

orientation = getOrientation(isqqpimsecure ? (arg1 + 180) : arg1, mCameraFacing == CAMERA_FACING_FRONT);
if (orientation == -1) return BAD_VALUE;
if (mOrientation != orientation) {
mOrientation = orientation;
if (mPreviewWindow != 0) {
native_window_set_buffers_transform(mPreviewWindow.get(),
mOrientation);
}
}
return OK;
}

2:在CameraService.cpp中的getCameraInfo修改。

status_t CameraService::getCameraInfo(int cameraId,
struct CameraInfo* cameraInfo) {
if (!mModule) {
return NO_INIT;
}

if (cameraId < 0 || cameraId >= mNumberOfCameras) {
return BAD_VALUE;
}

struct camera_info info;
status_t rc = mModule->get_camera_info(cameraId, &info);
cameraInfo->facing = info.facing;
cameraInfo->orientation = info.orientation;
if (cameraId == CAMERA_FACING_FRONT) {
int fd;
char buf[1024] = {0};
char value2[PROPERTY_VALUE_MAX];
property_get("ro.product.name", value2, "0");
bool isv10_yd=false;
if(strcmp(value2,"msm8x25_v10_w656_yd")==0){
isv10_yd=true;
}

snprintf(buf,1024,"/proc/%d/cmdline",getCallingPid());
if ((fd = open(buf,O_RDONLY)) != -1) {
if((read(fd, buf, 1023)) != -1) {
LOGE("getCameraInfo pid=%d, pname=%s", getCallingPid(), buf);
}
close(fd);
}

if (!isv10_yd && strcmp(buf, "com.tencent.mm") == 0) {
LOGE("getCameraInfo pid=%d, pname=%s modifty 180 for weixin", getCallingPid(), buf);
cameraInfo->orientation += 180;
}else if(strcmp(buf, "com.google.android.talk")==0){
cameraInfo->orientation += 180;
}
}
return rc;
}

二十:當手機沒有權限的時候,以下方法可以獲取權限,進行install或者push.

#mount
# mount -o remount /dev/block/mtdblock1 /system
# chmod 777 system/app

二十一:CTStest

4.1平台cts命令:單測試某個case: run cts -c class name -m case name 比如:run cts -c android.hardware.cts.CameraGLTest -m testCameraToSurfaceTextureMetadata
測試一個包: run cts -c class name; 比如:run cts -c android.hardware.cts.CameraGLTest


2.3平台cts命令:單測試某個case : start --plan CTS -t class name#case name ,比如,start --plan CTS -t android.hardware.cts.CameraGLTest#testCameraToSurfaceTextureMetadata
測試一個包:start --plan CTS -p class name, 比如: start --plan CTS -p android.hardware.cts.CameraGLTest

二十二:抓起tcpdump信息,tcpdump -i any -p -s 0 -w /sdcard/pcap.pcap

二十三:防止OOM代碼

public static int calculateInSampleSize(
BitmapFactory.Options options, int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;

if (height > reqHeight || width > reqWidth) {
if (width > height) {
inSampleSize = Math.round((float)height / (float)reqHeight);
} else {
inSampleSize = Math.round((float)width / (float)reqWidth);
}
}
return inSampleSize;
}

public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId,
int reqWidth, int reqHeight) {
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(res, resId, options);
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeResource(res, resId, options);
}

二十四:查看總內存信息:cat proc/meminfo

二十五:特殊符合表示

+-×÷
Java中使用+\u2212\u00d7\u00f7表示

二十六:使用命名合patch.
你現在有一個code base: small-src, 你的patch文件放在~/patch/0001-trival-patch.patch

cd small-src
git-am ~/patch/0001-trival-patch.patch

二十七:抓起視頻DUMP

1.Dump bit steam and outout yuv data
please run the below command before you test.
adb shell
// dump output yuv
setprop vidc.dec.log.out 1
//dump bit stream
setprop vidc.dec.log.in 1
You shall have the write permission in /data/misc/media

You will find the bitsteam and yuv data on /data/misc/media


2.Enable log.
please run the below command before you test.
a).Enable the omx debug
adb shell setprop vidc.debug.level 7
b.Enable the kernel log
adb shell

su
cd /d/msm_vidc
echo 0x1003 > debug_level
echo 0x3F > fw_level

二十八:命令輸入字符串到Edittext裡面
adb shell input text asdfsff

二十九:打印數組的內容:
直接打印Arrays.toString(數組名) 即可。

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved