当前位置: 代码迷 >> Android >> android开发中累积的小知识
  详细解决方案

android开发中累积的小知识

热度:60   发布时间:2016-04-28 06:19:25.0
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 <cutils/properties.h>
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(数组名) 即可。

  相关解决方案