您的位置:首页 > 移动开发 > Android开发

android 零星调试笔记(二)

2014-07-18 13:50 162 查看
续上篇:http://blog.csdn.net/jimbo_lee/article/details/8694265

通过包名获取其他包的Context实例

Context有个createPackageContext方法,可以创建另外一个包的上下文,这个实例不同于它本身的Context实例,但是功能是一样的。这个方法有两个参数:

1。packageName 包名,要得到Context的包名

2。flags 标志位,有CONTEXT_INCLUDE_CODE和CONTEXT_IGNORE_SECURITY两个选项。CONTEXT_INCLUDE_CODE的意思是包括代码,也就是说可以执行这个包里面的代码。CONTEXT_IGNORE_SECURITY的意思是忽略安全警告,如果不加这个标志的话,有些功能是用不了的,会出现安全警告。

java语言中byte[]与十六进制字符串转换

/**
* bytes转换成十六进制字符串
*/
public static String byte2HexStr(byte[] b) {
String hs = "";
String stmp = "";
for(int n = 0; n < b.length; n++){
stmp = (Integer.toHexString(b
& 0XFF));
if(stmp.length() == 1)
hs = hs + "0" + stmp;
else
hs = hs + stmp;
}
return hs.toUpperCase();
}

/**
* 十六进制字符串转换成bytes
*/
public static byte[] hexStr2Bytes(String src) {
int m = 0, n = 0;
int l = src.length() / 2;
byte[] ret = new byte[l];
for(int i = 0; i < l; i++){
m = i * 2 + 1;
n = m + 1;
ret[i] = uniteBytes(src.substring(i * 2, m), src.substring(m, n));
}
return ret;
}

private static byte uniteBytes(String src0,String src1) {
byte b0 = Byte.decode("0x" + src0).byteValue();
b0 = (byte) (b0 << 4);
byte b1 = Byte.decode("0x" + src1).byteValue();
byte ret = (byte) (b0 | b1);
return ret;
}

在处理byte数组与字符串转换的时候,可以使用中间类型十六进制字符串。

附: java中 byte字符处理

/**
*将字节数组补成8的倍数,以0填充;
*/
public static byte[] addZerosForDes(byte[] source)
{
byte [] ret = null;
if(source==null || source.length%8==0)
ret = source;
else
{
int i = source.length+8-source.length%8;
ret = new byte[i];
System.arraycopy(source,0,ret,0,source.length);
}
return ret;
}

/**
*将字节数组末尾的0去掉(小于8位);
*/
public static byte[] removeZerosForDes(byte[] encoding) {
byte[] ret = null;
if (encoding != null && encoding.length > 0) {
int i = encoding.length;
while (i-1>=0) {
if (encoding[i - 1] != (byte) 0)
break;
i--;
}
ret = new byte[i];
System.arraycopy(encoding, 0, ret, 0, i);
}
return ret;
}


如何判断字符串是否可以转换成数字

把bitmap图片转换成byte[]数据

InputStream inputStream = resource.openRawResource(resId);

Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
byte[] bitmapBuffer = bitmap2ByteArray(bitmap);

public static byte[] bitmap2ByteArray(Bitmap bitmap) {
int height = bitmap.getHeight();
int width = bitmap.getWidth();

byte[] tmpBuf = new byte[(height / 8 + 1) * width + 1];
int[] p = new int[8];
int t = 0;
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y += 8) {
for (int m = 0; m < 8; m++) {
if (y + m >= height){
p[m] = 0;
}else {
p[m] = (bitmap.getPixel(x, y + m) == -1 ? 0 : 1);
}
}
int value = p[0] * 128 + p[1] * 64 + p[2] * 32 + p[3] * 16 + p[4] * 8 + p[5] * 4 + p[6] * 2 + p[7];
tmpBuf[(++t)] = ((byte) value);
}
}
byte[] realBuf = new byte[t + 1];
for (int i = 0; i < t + 1; i++) {
realBuf[i] = tmpBuf[i];
}
return realBuf;
}


NDK开发中 在native方法中使用logcat:

第一步:在对应的mk文件中加入:LOCAL_LDLIBS := -llog
第二步:在要使用LOG的cpp文件中加入:
#include <android/log.h>
第三步:定义各个宏
#define LOG_TAG "nativeRfidUnpack"
#define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG , LOG_TAG, __VA_ARGS__)
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO  , LOG_TAG, __VA_ARGS__)
#define LOGW(...) __android_log_print(ANDROID_LOG_WARN  , LOG_TAG, __VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR  , LOG_TAG, __VA_ARGS__)
第四步:使用
LOGE("---Java_com_odm_rfid_RfidDevice_nativeDeviceUnpack ---");

NDK开发中使用第三方静态库的方法:

将NDK编译的第三方静态拷贝到JNI目录下,在Android.mk中添加如下代码
以openssl静态库(libcrypto-static.a)为例

第一种链接方法:LOCAL_LDFLAGS := libcrypto-static.a

第二种链接方法:LOCAL_LDLIBS := libcrypto-static.a

第三种链接方法:
include $(CLEAR_VARS)

LOCAL_MODULE := third_static_lib (可以随便起一个名字)

LOCAL_SRC_FILES := libcrypto-static.a

include $(PREBUILT_STATIC_LIBRARY)

//在你要编译的模块中引用third_static_lib

LOCAL_STATIC_LIBRARIES := third_static_lib

No implementation found for native Lcom/android/rfid/RfidUnPack;.nativeUnpackImage:([B[BI)I

在native的实现文件中开头加入代码:

namespace android {
<span style="white-space:pre">	</span>
#ifdef __cplusplus
extern "C" {
#endif

结尾加入代码:
#ifdef __cplusplus
}
#endif
}//namespace android

即ok了

判断闰年

if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0){
return true;
}else{
return false;
}

使用Eclipse的Export功能生成jar包:

一、打包成一般的jar包:

步骤如下:

1)在要打包的项目上右击,选择Export。

2)在弹出的窗口中,选择Java -> JAR File,然后点击next按钮。

3)在JAR File Specification窗口中,设置打包成的文件名和存放位置,点击两侧next。

4)在JAR Manifest Specification窗口中,设置MANIFEST.MF清单文件的配置,若仅仅打包成单纯的jar包的话,不用做任何修改,采取默认即可,若打包成可执行jar包的话,可以使用已存在的MANIFEST文件或者直接选择Main class。

5)点击Finish按钮,完成打包。

二、打包成可运行的jar包

步骤如下:

1)在要打包的项目上右击,选择Export。

2)在弹出的窗口中,选择Java -> Runnable JAR File,然后点击next按钮。

3)在Runnable JAR File Specification窗口中,选择Launch configuration和Export destination。

4)点击Finish按钮,打包完成。

拦截系统home键功能,即按home键不返回待机

在oncreate函数中增加代码

final android.view.Window win = getWindow();

win.addFlags(WindowManager.LayoutParams.FLAG_HOMEKEY_DISPATCHED);

或在调用setContentView函数之前增加代码

getWindow().setFlags(WindowManager.LayoutParams.FLAG_HOMEKEY_DISPATCHED, WindowManager.LayoutParams.FLAG_HOMEKEY_DISPATCHED);

Android.mk编译文件中 LOCAL_MODULE_TAGS选项的含义:

LOCAL_MODULE_TAGS :=user eng tests optional

user: 指该模块只在user版本下才编译

eng: 指该模块只在eng版本下才编译

tests: 指该模块只在tests版本下才编译

optional:指该模块在所有版本下都编译

Java中 String.formatter 的应用

long now = System.currentTimeMillis();

String s = String.format("%tR", now);// "15:12"

Date d = new Date(now);

s = String.format("%tD", d);// "07/13/04" // Current month/day/year

s = String.format("%,d", Integer.MAX_VALUE); // "2,147,483,647"

s = String.format("%05d", 123); // "00123"

格式: %[argument_index$][flags][width][.precision]conversion

可选的 argument_index 是一个十进制整数,用于表明参数在参数列表中的位置。第一个参数由 "1$" 引用,第二个参数由 "2$" 引用,依此类推。

可选的 flags 是修改输出格式的字符集。有效标志的集合取决于转换类型。

可选 width 是一个非负十进制整数,表明要向输出中写入的最少字符数。

可选 precision 是一个非负十进制整数,通常用来限制字符数。特定行为取决于转换类型。

所需的 conversion 是一个表明应该如何格式化参数的字符。给定参数的有效转换集合取决于参数的数据类型。

对于日期、时间 第一个字符是 't' 或 'T'。第二个字符表明所使用的格式 具体格式参考 类 java.util.Formatter
示例代码:

Double d = 12.3366;
System.out.println(String.format("%2$08d", -3123,-5566));
System.out.println(String.format("%1$9d", -31));
System.out.println(String.format("%1$-9d", -31));
System.out.println(String.format("%1$(9d", -31));
System.out.println(String.format("%1$#9x", 5689));

//小数点后面两位
System.out.println(String.format("%1$.2f", 5689.0)); //必须是同类型的才能进行转换

//格式化的位置
/*String str = "I love ni %s, you love me %s";
String str2 = "I love ni %2$s, you love me %1$s";

System.out.println(String.format(str, "abcdefg","1234567"));

System.out.println(String.format(str2, "abcdefg","1234567"));*/

//数组的操作
Object[] sendData = new Object[4];
sendData[0] = Integer.valueOf(1);
sendData[1] = "172.12.1.2";
sendData[2] = Integer.valueOf(123);
sendData[3] = "testadfaerfa";
String sendDataString = String.format("%d,%s,%d,%s",(Object[]) sendData);
System.out.println(sendDataString);
http://blog.csdn.net/feng_870906/article/details/6870788

全测试monkey指令

adb shell monkey --ignore-crashes --ignore-timeouts --ignore-security-exceptions --monitor-native-crashes --ignore-native-crashes 10000000

静态壁纸,调整壁纸显示位置

KK版本 修改文件:packages/apps/Launcher3/src/com/android/launcher3/Workspace.java

public void syncWithScroll() {
if(enableWallpaperScroll){
//ori code -- 会根据当前screen位置调整墙纸位置
float offset = wallpaperOffsetForCurrentScroll();
mWallpaperOffset.setFinalX(offset);
}else{
//新增code -- 不会根据当前screen位置调整墙纸位置, 仅根据当前手机方向(GSensor方向)调整墙纸位置
if(mLauncher.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE){
mWallpaperOffset.setFinalX((float) 0.55);
}else{
mWallpaperOffset.setFinalX((float) 0.48);
}
}
updateOffset(true);
}

判断当前手机是横屏还是竖屏

mLauncher.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE

手机eng、user版本互转

int sdkVersion = SystemProperties.getInt(ANDROID_BUILD_VERSION, 10);
if(sdkVersion >= ANDROID_BUILD_ICS){
toRoot_ics();
}else{
toRoot_gb();
}
private static final String RO_ADB_SECURE = "ro.adb.secure";
private static final String RO_SECURE = "ro.secure";
private static final String RO_ALLOW_MOCK_LOCATION="ro.allow.mock.location";
private static final String RO_DEBUG = "ro.debuggable";
private static final String ADB_ENABLE_GB = "persist.service.adb.enable";
private static final String ADB_ENABLE_ICS = "persist.sys.usb.config";
private static final String ATCI_USERMODE = "persist.service.atci.usermode";

private void toRoot_ics(){
SystemProperties.set(ADB_ENABLE_ICS, "none");
//SystemProperties.set("ctl.stop", "adbd");
SystemProperties.set(RO_SECURE, "0");
SystemProperties.set(RO_ADB_SECURE, "0");
//SystemProperties.set(RO_ALLOW_MOCK_LOCATION,"1" );
SystemProperties.set(RO_DEBUG, "1");
SystemProperties.set(ADB_ENABLE_ICS, "mass_storage,adb,acm");
//SystemProperties.set("ctl.start", "adbd");
SystemProperties.set(ATCI_USERMODE, "1");
try {
Process proc = Runtime.getRuntime().exec("start atcid-daemon-u");
} catch (IOException e) {
e.printStackTrace();
}
Toast.makeText(User2rootActivity.this, "Update to Root Success", Toast.LENGTH_LONG).show();
}

private void toUser_ics(){
SystemProperties.set(ATCI_USERMODE, "0");
try {
Process proc = Runtime.getRuntime().exec("stop atcid-daemon-u");
} catch (IOException e) {
e.printStackTrace();
}
SystemProperties.set(ADB_ENABLE_ICS, "mass_storage");
SystemProperties.set(RO_SECURE, "1");
SystemProperties.set(RO_ADB_SECURE, "1");
//SystemProperties.set(RO_ALLOW_MOCK_LOCATION,"0" );
SystemProperties.set(RO_DEBUG, "0");

Toast.makeText(User2rootActivity.this, "Update to User Success", Toast.LENGTH_LONG).show();
}

private void toRoot_gb(){
SystemProperties.set(RO_SECURE, "0");
SystemProperties.set(RO_ALLOW_MOCK_LOCATION,"1" );
SystemProperties.set(RO_DEBUG, "1");
SystemClock.sleep(200);
SystemProperties.set(ADB_ENABLE_GB, "1");
Toast.makeText(User2rootActivity.this, "Update to Root Success", Toast.LENGTH_LONG).show();
}

private void toUser_gb(){
SystemProperties.set(RO_SECURE, "1");
SystemProperties.set(RO_ALLOW_MOCK_LOCATION,"0" );
SystemProperties.set(RO_DEBUG, "0");
SystemProperties.set(ADB_ENABLE_GB, "0");
Toast.makeText(User2rootActivity.this, "Update to User Success", Toast.LENGTH_LONG).show();
}

startActivityForResult onActivityReult需要注意的事项

1、被startActivityForResult启动的acitvity的启动模式不能是singleInstance或singleTask android:launchMode="singleTask" 否则 函数onActivityResult会被立即执行,子Activity是singleTask,父Activity是singleTask也不行,把子Activity改为标准的才行
2、startActivityForResult调用时 requestCode 必须>0 才行,否则onActivityResult不会被调用

修改已经提交了的log (git commit -m"log")

1、如果是前一个提交,可以用 git commit --amend -m "" 或 git commit --amend 来改

2、更早这样修改:假设要修改commit 65ae4f,执行

git rebase 65ae4f^ --interactive

在编辑器中把第一行的pick改为edit,保存,退出,然后按提示操作。

一般是第一种情况比较多,如果不是前一个提交也可以使用git reset commitID 把那个commit放到前一个提交,不过后面的提交要重新git add -> git commit 提交

ubuntu Terminal终端配色方案

文字颜色:#708284

背景颜色:#07242E

近似默认:文字颜色:#FFFFFF 背景:#270C1F

android中的ellipsize属性

textview中有个内容过长加省略号的属性,即ellipsize

用法如下:

在xml中

android:ellipsize = "end"   省略号在结尾

android:ellipsize = "start"   省略号在开头

android:ellipsize = "middle" 省略号在中间

android:ellipsize = "marquee" 跑马灯

最好加一个约束android:singleline = "true"

当然也可以用代码语句

tv.setEllipsize(TextUtils.TruncateAt.valueOf("END"));

tv.setEllipsize(TextUtils.TruncateAt.valueOf("START"));

tv.setEllipsize(TextUtils.TruncateAt.valueOf("MIDDLE"));

tv.setEllipsize(TextUtils.TruncateAt.valueOf("MARQUEE"));

最好再加一个约束tv.setSingleLine(true);

不仅对于textview有此属性,对于editext也有,不过它不支持marquee

SQL通配符字符的搜索

SELECT * FROM tablename WHERE intent LIKE '%$%%' escape '$' 其中$可以是任何字符

这句话就是在tablename中搜索字段 intent 含有%字符的数据

Linux 延时执行命令

NAME

sleep - delay for a specified amount of time

SYNOPSIS

sleep NUMBER[SUFFIX]...

sleep OPTION

DESCRIPTION

Pause for NUMBER seconds. SUFFIX may be `s' for seconds (the default), `m' for minutes, `h' for hours or

`d' for days. Unlike most implementations that require NUMBER be an integer, here NUMBER may be an arbi‐

trary floating point number. Given two or more arguments, pause for the amount of time specified by the

sum of their values.

eg: date;sleep 10s;date 先显示当前日期 暂停10秒钟,再显示日期 结果如下:
Thu Jun 11 17:35:03 CST 2015

Thu Jun 11 17:35:13 CST 2015

Unable to add window android.view.ViewRootImpl

用到了悬浮按钮,报这个错误,Caused by: android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@4129fe70 -- permission denied for this window
type,原因是没有加权限。 <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

android系统如何在静音模式下关闭camera拍照声音

在CameraService.cpp文件中,关于调用playsound()函数的地方加入如下判断:


注意:property_get()函数需要引入头文件,<cutils/properties.h>


Ubuntu12.04下eclipse提示框黑色背景色的修改方法

eclipse提示框的背景颜色使用的是系统的提示框颜色配置,在windows下为黄色,但在Ubuntu12.04(gnome)下却是黑色,造成提示内容很难看清。在eclipse中我们是无法修改这个颜色的配置的,只能通过修改系统的颜色配置。在ubuntu11.10以前,我们是可以能过自定义系统外观来修改这一颜色的配置的,但自ubuntu11.10以后,就没有相关的操作界面了,只能通过修改配置文件的方式实现了。这个文件位于/usr/share/themes/下对应的主题文件夹下,如你使用Radiance主题,就进入到/usr/share/themes/Radiance/目录下,

cd /usr/share/themes/Radiance

打开gtk-2.0/gtkrc文件,

sudo vim gtk-2.0/gtkrc
修改第一行的tooltip_fg_color和tooltip_bg_color两个属性的值,如果没有改属性,可以自行添加,其值仿照windows的默认值,分别设定位:

tooltip_fg_color:#000000

tooltip_bg_color:#f2edbc

然后保存退出,打开系统外观配置,切换一下主题,当切换回来的时候,修改的效果就生效了。

错误解决: java.lang.SecurityException: Permission Denial

应用场景:在一个app中的activity中通过包名、类名启动另外一个app中的activity 下例为在contacts中启动factoryMode中的activity
错误:01-01 08:04:09.009: W/System.err(771): java.lang.SecurityException: Permission Denial: starting Intent { cmp=com.mediatek.factorymode/.versionsdialog.InternalVersion
} from ProcessRecord{e742bbe 3224:com.yunos.alicontacts/u0a1} (pid=3224, uid=10001) not exported from uid 1000
解决方案: 在目的activity中增加属性 android:exported="true"
<activity

android:name="com.mediatek.factorymode.versionsdialog.InternalVersion"

android:exported="true"

android:theme="@android:style/Theme.Dialog" />

<activity

Android Layout 中”@+id”、”@id”和”@android:id/”、”?android:attr”区别

@表示引用资源,声明这是一个资源引用—随后的文本是以@[package:]type/name形式提供的资源名。

@android:string表明引用的系统的(android.*)资源

@string表示引用应用内部资源

对于id, 可以用@+id表明创建一个id

?表示引用属性

“?”引用主题属性,当您使用这个标记,你所提供的资源名必须能够在主题属性中找到,因为资源工具认为这个资源属性是被期望得到的,您不需要明确的指出它的类型(?android:attr/android:textDisabledColor)

紧急拨号列表

vendor/mediatek/proprietary/external/EccList/ecc_list.xml

TextView属性大全

XML属性

android:autoLink 是否自动链接网址或邮箱地址;

android:autoText 自动检测错误;

android:bufferType 决定getText()返回的类型

android:capitalize 指定使用类型

android:cursorVisible 光标是否可见

android:digits 数字输入

android:drawableBottom 内容显示在文字的下边

android:drawableEnd 内容显示在文字的结尾

android:drawableLeft 内容显示在文字的左边

android:drawablePadding 内容和文字之间的空隙

android:drawableRight 内容显示在文字的右边

android:drawableStart 内容显示在文字的开始

android:drawableTop 内容显示在文字的上边

android:editable 编辑功能,能够使用输入法

android:editorExtras 编辑功能扩展,用户设置

android:ellipsize 椭圆区域的显示方式

android:ems 可以在更多系统上运行

android:fontFamily 字体风格

android:freezesText 冻结在光标位置

android:gravity 文字小于显示范围时,x和y轴方向的调整

android:height 文字像素高度

android:hint 文本空白时的提示语

android:imeActionId 激活输入法ID序号

android:imeActionLabel 激活输入法符号

android:imeOptions 输入法操作

android:includeFontPadding 足够空间容纳字体显示

android:inputMethod 指定输入法

android:inputType 选择输入法

android:lineSpacingExtra 额外的文字间距

android:lineSpacingMultiplier 额外的文字间距,乘数

android:lines 多行显示

android:linksClickable 点击链接

android:marqueeRepeatLimit 跑马灯重复限制

android:maxEms 最大系统兼容

android:maxHeight 最大文本高度

android:maxLength 最大文本长度

android:maxLines 最大文本行数

android:maxWidth 最大文本长度

android:minEms 最小系统兼容

android:minHeight 最小文本高度

android:minLines 最小文本行数

android:minWidth 最小文本宽度

android:numeric 支持数字输入

android:password 文本作为密码

android:phoneNumber 支持电话号码输入

android:privateImeOptions 私人输入操作

android:selectAllOnFocus 点击全部选中

android:shadowColor 阴影颜色

android:shadowDx 阴影水平偏移

android:shadowDy 阴影垂直偏移

android:shadowRadius 阴影半径

android:singleLine 单行显示

android:text 显示文本

android:textAllCaps 文本全部大写

android:textAppearance 基本的文字颜色,字体,大小,风格

android:textColor 文本颜色

android:textColorHighlight 文本高亮颜色

android:textColorHint 文本提示颜色

android:textColorLink 链接文本颜色

android:textIsSelectable 文本能够被选中

android:textScaleX 水平缩放参数

android:textSize 文本大小

android:textStyle 文本风格

android:typeface 文本字体

android:width 文本宽度

Android中Intent对应的category列表大全

android.intent.category.ALTERNATIVE  

  android.intent.category.BROWSABLE  

  android.intent.category.DEFAULT

  android.intent.category.DEVELOPMENT_PREFERENCE  

  android.intent.category.EMBED  

  android.intent.category.HOME  

  android.intent.category.INFO  

  android.intent.category.LAUNCHER  

  android.intent.category.MONKEY  

  android.intent.category.OPENABLE  

  android.intent.category.PREFERENCE  

  android.intent.category.SELECTED_ALTERNATIVE  

  android.intent.category.TAB

  Android 2.0,2.0.1,2.1 新增车座和充电座

  android.intent.category.CAR_DOCK  

  android.intent.category.DESK_DOCK

  Android 2.2 新增行车模式

  android.intent.category.CAR_MODE

  ALTERNATIVE

  你将在这章的后面所看到的,一个 Intent Filter 的用途是使用动作来帮忙填入上下文菜单。 ALTERNATIVE 种类指定,在某种数据类型的项目上可以替代默认执行的动作。例如,一个联系人的默认动作时浏览它,替代的可能是去编辑或删除它。  

SELECTED_ALTERNATIVE

  与 ALTERNATIVE 类似,但 ALTERNATIVE 总是使用下面所述的 Intent 解析来指向单一的动作。SELECTED_ALTERNATIVE在需要一个可能性列表时使用。

BROWSABLE

  指定在浏览器中的动作。当 Intent 在浏览器中被引发,都会被指定成 BROWSABLE 种类。
DEFAULT

  设置这个种类来让组件成为 Intent Filter 中定义的 data 的默认动作。这对使用显式 Intent 启动的 Activity 来说也是必要的。

GADGET

  通过设置 GADGET 种类,你可以指定这个 Activity 可以嵌入到其他的 Activity 来允许。

HOME

  HOME Activity 是设备启动(登陆屏幕)时显示的第一个 Activity 。通过指定 Intent Filter 为 HOME 种类而不指定动作的话,你正在将其设为本地 home 画面的替代。

LAUNCHER

  使用这个种类来让一个 Activity 作为应用程序的启动项。

data

  data 标签允许你指定组件能作用的数据的匹配;如果你的组件能处理多个的话,你可以包含多个条件。你可以使用下面属性的任意组合来指定组件支持的数据

android:host

  指定一个有效的主机名(例如, com.google )。

android:mimetype

  允许你设定组件能处理的数据类型。例如,<type android:value=”vnd.android.cursor.dir/*”/>能匹配任何 Android 游标。

android:path

  有效地 URI 路径值(例如, /transport/boats/ )。

android:port

  特定主机上的有效端口。

android:scheme

  需要一个特殊的图示(例如, content 或 http )。

常用的MIME类型

.doc application/msword

.docx application/vnd.openxmlformats-officedocument.wordprocessingml.document

.rtf application/rtf

.xls application/vnd.ms-excel application/x-excel

.xlsx application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

.ppt application/vnd.ms-powerpoint

.pptx application/vnd.openxmlformats-officedocument.presentationml.presentation

.pps application/vnd.ms-powerpoint

.ppsx application/vnd.openxmlformats-officedocument.presentationml.slideshow

.pdf application/pdf

.swf application/x-shockwave-flash

.dll application/x-msdownload

.exe application/octet-stream

.msi application/octet-stream

.chm application/octet-stream

.cab application/octet-stream

.ocx application/octet-stream

.rar application/octet-stream

.tar application/x-tar

.tgz application/x-compressed

.zip application/x-zip-compressed

.z application/x-compress

.wav audio/wav

.wma audio/x-ms-wma

.wmv video/x-ms-wmv

.mp3 .mp2 .mpe .mpeg .mpg audio/mpeg

.rm application/vnd.rn-realmedia

.mid .midi .rmi audio/mid

.bmp image/bmp

.gif image/gif

.png image/png

.tif .tiff image/tiff

.jpe .jpeg .jpg image/jpeg

.txt text/plain

.xml text/xml

.html text/html

.css text/css

.js text/javascript

.mht .mhtml message/rfc822

默认搜索引擎的修改:

默认搜索引擎设为google

diff --git a/frameworks/base/services/core/java/com/mediatek/search/SearchEngineManagerService.java b/frameworks/base/se

index 0835085..f66dc55 100755

--- a/frameworks/base/services/core/java/com/mediatek/search/SearchEngineManagerService.java

+++ b/frameworks/base/services/core/java/com/mediatek/search/SearchEngineManagerService.java

@@ -167,9 +167,6 @@ public class SearchEngineManagerService extends ISearchEngineManagerService.Stub

if(SystemProperties.getBoolean("ro.coolpad",false)){

searchEngines = res.getStringArray(com.mediatek.internal.R.array.coolpad_new_search_engines);

}

- if(SystemProperties.getBoolean("ro.haier",false)){

- searchEngines = res.getStringArray(com.mediatek.internal.R.array.new_search_engines_haier);

- }

if (null == searchEngines || 1 >= searchEngines.length) {

// todo: throws an exception in this case.

diff --git a/vendor/mediatek/proprietary/frameworks/base/res/res/values/donottranslate-new-search_engines.xml b/vendor/m

index 5331a73..069df47 100755

--- a/vendor/mediatek/proprietary/frameworks/base/res/res/values/donottranslate-new-search_engines.xml

+++ b/vendor/mediatek/proprietary/frameworks/base/res/res/values/donottranslate-new-search_engines.xml

@@ -37,10 +37,4 @@

<item>baidu_English--Baidu--baidu.com--search_engine_baidu--http://m.baidu.com/s?from=1089a&word={searchTerms}&

<item>bing--Bing--bing.com--search_engine_bing--http://www.bing.com/search?q={searchTerms}--UTF-8--http://api.bing.

</string-array>

- <string-array name="new_search_engines_haier" translatable="false">

- <item>--</item>

- <item>google--Google--google.com--search_engine_google--http://www.google.com/m?hl={language}&ie={inputEncoding

- <item>yahoo--Yahoo!--yahoo.com--search_engine_yahoo--https://search.yahoo.com/search?ei={inputEncoding}&.tsrc=m

- <item>bing--Bing--bing.com--search_engine_bing--http://www.bing.com/search?q={searchTerms}--UTF-8--http://api.bing.

- </string-array>

</resources>

diff --git a/vendor/mediatek/proprietary/frameworks/base/res/res/values/symbols.xml b/vendor/mediatek/proprietary/framew

index e4ae534..ee07099 100755

--- a/vendor/mediatek/proprietary/frameworks/base/res/res/values/symbols.xml

+++ b/vendor/mediatek/proprietary/frameworks/base/res/res/values/symbols.xml

@@ -341,8 +341,7 @@

<java-symbol type="array" name="new_search_engines" />

<java-symbol type="array" name="no_google_search_engines" />

<java-symbol type="array" name="coolpad_new_search_engines" />

- <java-symbol type="array" name="new_search_engines_haier" />

<java-symbol type="string" name="wday_year_month_day" />

<java-symbol type="string" name="wday_year_day_month" />

<java-symbol type="string" name="wday_month_day_year" />

vendor/mediatek/proprietary/frameworks/base/res/res/values/donottranslate-new-search_engines.xml 完整示例:

<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">

<string-array name="new_search_engines" translatable="false">

<item>--</item>

<item>baidu_English--Baidu--baidu.com--search_engine_baidu--http://m.baidu.com/s?from=1011857c&ie=utf8&word={searchTerms}--UTF-8--http://suggestion.baidu.com/su?wd={searchTerms}</item>

<item>bing--Bing--bing.com--search_engine_bing--http://www.bing.com/search?q={searchTerms}--UTF-8--http://api.bing.com/osjson.aspx?query={searchTerms}&language={language}</item>

</string-array>

<string-array name="coolpad_new_search_engines" translatable="false">

<item>--</item>

<item>baidu_English--Baidu--baidu.com--search_engine_baidu--http://m.baidu.com/s?from=1089a&word={searchTerms}&ua=bd_854_480_coolpad*5270_1.10--UTF-8--http://suggestion.baidu.com/su?wd={searchTerms}</item>

<item>bing--Bing--bing.com--search_engine_bing--http://www.bing.com/search?q={searchTerms}--UTF-8--http://api.bing.com/osjson.aspx?query={searchTerms}&language={language}</item>

</string-array>

</resources>

动态获取文本在窗口中占用的长度

Paint p = new Paint();

p.setTextSize(textSize)

int markTextLen = (int)p.measureText(str);

MTK平台送CTA注意事项

1.MTK_CTA_SUPPORT=yes

2.DM短信自注册关闭,关闭

mediatek/config/<project>/custom.conf

dm.SmsRegState=0

3.号码识别11位

4.删除移动适配包(如下路径):

vendor/mediatek/<project>/artifacts/out/target/product/lt;project>//system/vendor/operator/

5.一定要打开user2root切换,最好使用mtk原始的工模指令,入库也一样;

6.权限管理默认开启;

7.发布eng版本。

ListView焦点问题

如果在一个ListView上面放置一个可以接收焦点的东西,比如Button,当使用向上方向键滚动ListView到第一条后,焦点会移到上面的Button上,这个没问题。但然后使用向下的方向键时,焦点会跳到ListView中当前窗口的最下面一条,而不是焦点离开时的第一条。在ListView下方有Button的时候,向上移动焦点,也会出现类似的情况。

方法一:重写ListView OnFocusChanged()方法
protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
if (gainFocus && previouslyFocusedRect != null) {
final ListAdapter adapter = getAdapter();
final int count = adapter.getCount();
switch (direction) {
case FOCUS_DOWN:
for (int i = 0; i < count; i++) {
if (!adapter.isEnabled(i)) {
continue;
}
setSelection(i);
break;
}
break;
case FOCUS_UP:
for (int i = count-1; i>=0; i--) {
if (!adapter.isEnabled(i)) {
continue;
}
setSelection(i);
break;
}
break;
default:
break;
}
}
}
方法二:
给listView增加属性 android:descendantFocusability="blocksDescendants"
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: