Archives for: July 2011
How to delete SMS from android inbox?
July 23rd, 2011The first method is to use "content://sms/{sms_id}", but unfortunately, this metod doesn't work due to a unknown reason.
The workable solution is to use uri "content://sms", and use condition "id = {smsid}". It can delete SMS from inbox.
How to trun on Android SQLite Trace
July 23rd, 2011Based on the code of
JNI code output log in logcat
July 6th, 2011
#include <android/log.h>
#define LOG_TAG "SCWS"
#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__)
Tips about JNI code
July 6th, 2011Today, I fixed two stupid defects in my JNI code.
First one, I notice that return java string always contain a extra character, finally, it is caused by a mistake in my code: put 0 in [length+1] instead of [length]. VERY STUPID.
Second one, I notice the output of string is not correct. I write unicode string literatelly from txt file of windows notepad. At end, I found that java always uses Big Endian utf-16, but windows notpad using Little Endian utf-16.
Access asset in JNI code
July 6th, 2011In one project, I need to access asset in JNI code. After googling some links, I got a negative conclusion.
Officially interface: AssetManager
Officially, android only provides java interface to access asset through AssetManager.
This interface provides app an InputStream instance, an offset, a size. Based on this, java app can uses them to read asset file content.
Underground information
Currently, asset files are zipped into apk. Excepts png files, other files are compressed. The officially interface provides an InputStream which can decompress apk file.
Solution based on officially interface
JNI code can call java method esp. AssetManager and InputStream interface to directly read asset data. But if your native code need to use standard fopen/open api, this method can't help you.
Underground solution
Based on underground information, one solution is enabled: Use SystemInfo to query apk path. Use AssertManager to get offset and length. Use fopen and zip lib to read data.
Another officially solution
Use AssertManager interface to read asset data and copy to another file. JNI code to access new file.
WWW Resources
Android: How to make game asset files readable from c++ code using ndk File Operations in Android NDK fopen file from resource package? Read static files through NDK Working with SDCard’s filesystem in Android
JNI programming
July 5th, 2011Document
For developing android application, I have researched JNI a bit. Following two link is a must-have link for JNI programming:
The Java Native Interface Programmer's Guide and Specification
Simple Guide
First, you must install NDK and write Android.mk as it said.
Second, you write a java file which contains native method define.
Using javah command to generate header file for jni. javah -class bin/classes com.???.???.????
Implement functions defined in this header file.
Make sure add following lines in to java file.
static {
System.loadLibrary("scws-jni");
}
Short name for git repo
July 4th, 2011Create .gitconfig file in your home foler.
put following content in it:
[remote "smsrepo"]
url = D:\\personal\\and\\gitrepos\\android\\sms_utils.git
Android UserAgent
July 4th, 2011frameworks/base/core/java/android/webkit/WebSettings.java#getUserAgentString() returns useragent string. Analyze it, it logic is:
if( user specify "DESKTOP like UA" or "IPHONE like UA ){
return this type UA.
}
if( user specify UA ){ return UA; }
return getCurrentUserAgent(); getCurrentUserAgent() retrieve string template from resource com.android.internal.R.string.webuseragent( defined in frameworks/base/core/res/res/values/ ), combine with BUILD and LANGUAGE information to generate default ANDROID user agent.
packages/apps/Browser/src/com/android/browser/BrowserSettings.java in this file, setUserAgentString() will be used to specify UserAgentString() for Browser.