編輯:關於Android編程
MediaScannerJNI的在MediaScanner中的地位可參考
Android MediaScanner 總綱
MediaScanner JNI文件名:
android_media_MediaScanner.cpp
位置:
frameworksasemediajniandroid_media_MediaScanner.cpp
android_media_MediaScanner是JAVA層和server層溝通的一個橋梁
android_media_MediaScanner中有一個MyMediaScannerClient是一個調用JAVA層android/media/MediaScannerClient的入口是Native層想java層通信的橋梁。<喎?/kf/ware/vc/" target="_blank" class="keylink">vcD4NCjxzdmcgaGVpZ2h0PQ=="260" version="1.1" width="634" xmlns="http://www.w3.org/2000/svg">
在MediaScanner.java初始化中過程調用,其核心是創建了一個StagefrightMediaScanner
static {
System.loadLibrary(media_jni);
native_init();
}
public MediaScanner(Context c) {
native_setup();
......
}
native_init 對應 android_media_MediaScanner_native_init
native_setup對應android_media_MediaScanner_native_setup
static void
android_media_MediaScanner_native_setup(JNIEnv *env, jobject thiz)
{
ALOGV(native_setup);
MediaScanner *mp = new StagefrightMediaScanner;
......
env->SetLongField(thiz, fields.context, (jlong)mp);
}
調用MediaScanner.cpp實現processDirectory完成工作
在MediaScanner.java中調用scanDirectories,詳見Android MediaScanner源代碼解析 第6節
其功能還是通過MediaScanner.cpp的processDirectory實現對
static void
android_media_MediaScanner_processDirectory(
JNIEnv *env, jobject thiz, jstring path, jobject client)
{
MediaScanner *mp = getNativeScanner_l(env, thiz);
.......
const char *pathStr = env->GetStringUTFChars(path, NULL);
MyMediaScannerClient myClient(env, client);
MediaScanResult result = mp->processDirectory(pathStr, myClient);
env->ReleaseStringUTFChars(path, pathStr);
}
調用StageFrightMediaScanner.cpp實現processFile完成工作
static void
android_media_MediaScanner_processFile(
JNIEnv *env, jobject thiz, jstring path,
jstring mimeType, jobject client)
{
// Lock already hold by processDirectory
MediaScanner *mp = getNativeScanner_l(env, thiz);
const char *pathStr = env->GetStringUTFChars(path, NULL);
const char *mimeTypeStr =
(mimeType ? env->GetStringUTFChars(mimeType, NULL) : NULL);
........
MyMediaScannerClient myClient(env, client);
MediaScanResult result = mp->processFile(pathStr, mimeTypeStr, myClient);
}
引用android/media/MediaScannerClient中scanFile,handleStringTag, setMimeType三個接口
jclass mediaScannerClientInterface =
env->FindClass(kClassMediaScannerClient);
if (mediaScannerClientInterface == NULL) {
ALOGE(Class %s not found, kClassMediaScannerClient);
} else {
mScanFileMethodID = env->GetMethodID(
mediaScannerClientInterface,
scanFile,
(Ljava/lang/String;JJZZ)V);
mHandleStringTagMethodID = env->GetMethodID(
mediaScannerClientInterface,
handleStringTag,
(Ljava/lang/String;Ljava/lang/String;)V);
mSetMimeTypeMethodID = env->GetMethodID(
mediaScannerClientInterface,
setMimeType,
(Ljava/lang/String;)V);
}
本文實例為大家分享了Android實現手機自動獲取短信驗證碼功能,供大家參考,具體內容如下1、短信監聽廣播2、讀取短信內容3、截取短信內容【可以 reg截取】4、填寫至相
繼承TabActivity並以activity布局先查看下最終效果圖:再看下代碼結構:其中black.gif顧名思義就是一個黑背景圖片,grey.gif就是一張灰色的背景
Android平台已經給我們提供了很多標准的組件,如:TextView、EditView、Button、ImageView、Menu等,還有許多布局控件,常見的有:Abs
1.TextView Textview在之前的學習中用到過好多次,就不再貼代碼了,在第四天學到的新知識是對齊方式,在activity_main中創建TextVi