android源码中,在系统多媒体数据库中增加一个字段
由于项目需求,在系统多媒体管理数据库里的存储图像文件的表中需要新增加一个字段,源码在:项目\packages\providers\MediaProvider\MediaProvider.java下,在updateDatabase()方法里,你会发现images表格是由files创建的一个视图,于是,在files的创建里增加了一个字段,如下:
....
db.execSQL("CREATE TABLE files (" +
"_id INTEGER PRIMARY KEY AUTOINCREMENT," +
"_data TEXT," + // this can be null for playlists
"_size INTEGER," +
"format INTEGER," +
"parent INTEGER," +
"date_added INTEGER," +
"date_modified INTEGER," +
"mime_type TEXT," +
"title TEXT," +
"description TEXT," +
"_display_name TEXT," + // for images
"picasa_id TEXT," +
"orientation INTEGER," + // for images and video
"latitude DOUBLE," +
"longitude DOUBLE," +
"datetaken INTEGER," +
"mini_thumb_magic INTEGER," +
"bucket_id TEXT," +
"bucket_display_name TEXT," +
"isprivate INTEGER," +
"is_upload INTEGER," + //----------新增字段 // for audio
"title_key TEXT," +
"artist_id INTEGER," +
"album_id INTEGER," +
"composer TEXT," +
"track INTEGER," +
"year INTEGER CHECK(year!=0)," +
"is_ringtone INTEGER," +
"is_music INTEGER," +
"is_alarm INTEGER," +
"is_notification INTEGER," +
"is_podcast INTEGER," +
"is_doorbell INTEGER," +
"is_auto_alarm INTEGER,"+
"album_artist TEXT," + // for audio and video
"duration INTEGER," +
"bookmark INTEGER," + // for video
"artist TEXT," +
"album TEXT," +
"resolution TEXT," +
"tags TEXT," +
"category TEXT," +
"language TEXT," +
"mini_thumb_data TEXT," + // for playlists
"name TEXT," + // media_type is used by the views to emulate the old
// images, audio_meta, videos and audio_playlist tables.
"media_type INTEGER," + // Value of _id from the old media table.
// Used only for updating other tables during database upgrade.
"old_id INTEGER," +
"isaccurateduration INTEGER" +
");");
在images视图创建时,也增加了该字段
private static final String IMAGE_COLUMNS =
"_data,_size,_display_name,mime_type,title,date_added," +
"date_modified,description,picasa_id,isprivate,latitude,longitude," +
"datetaken,orientation,mini_thumb_magic,bucket_id,bucket_display_name," +
"width,height,is_upload";
编译后,把apk push到system/priv-app下一看,发现运行错误:
03-01 09:31:24.367: E/AndroidRuntime(1065): java.lang.RuntimeException: Unable to get provider com.android.providers.media.MediaProvider: android.database.sqlite.SQLiteException: no such column: drm_content_uri (code 1): , while compiling: CREATE VIEW audio_meta AS SELECT _id,_data,_display_name,_size,mime_type,date_added,is_drm,date_modified,title,title_key,duration,artist_id,composer,album_id,track,year,is_ringtone,is_music,is_alarm,is_notification,is_podcast,is_doorbell,is_auto_alarm,bookmark,album_artist,drm_content_uri,drm_offset,drm_dataLen,drm_rights_issuer,drm_content_name,drm_content_description,drm_content_vendor,drm_icon_uri,drm_method,title_pinyin_key FROM files WHERE media_type=2;
03-01 09:31:24.367: E/AndroidRuntime(1065): at android.app.ActivityThread.installProvider(ActivityThread.java:5011)
03-01 09:31:24.367: E/AndroidRuntime(1065): at android.app.ActivityThread.installContentProviders(ActivityThread.java:4582)
03-01 09:31:24.367: E/AndroidRuntime(1065): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4522)
03-01 09:31:24.367: E/AndroidRuntime(1065): at android.app.ActivityThread.access$1500(ActivityThread.java:151)
03-01 09:31:24.367: E/AndroidRuntime(1065): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1381)
03-01 09:31:24.367: E/AndroidRuntime(1065): at android.os.Handler.dispatchMessage(Handler.java:110)
03-01 09:31:24.367: E/AndroidRuntime(1065): at android.os.Looper.loop(Looper.java:193)
03-01 09:31:24.367: E/AndroidRuntime(1065): at android.app.ActivityThread.main(ActivityThread.java:5292)
03-01 09:31:24.367: E/AndroidRuntime(1065): at java.lang.reflect.Method.invokeNative(Native Method)
03-01 09:31:24.367: E/AndroidRuntime(1065): at java.lang.reflect.Method.invoke(Method.java:515)
03-01 09:31:24.367: E/AndroidRuntime(1065): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
03-01 09:31:24.367: E/AndroidRuntime(1065): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
03-01 09:31:24.367: E/AndroidRuntime(1065): at dalvik.system.NativeStart.main(Native Method)
03-01 09:31:24.367: E/AndroidRuntime(1065): Caused by: android.database.sqlite.SQLiteException: no such column: drm_content_uri (code 1): , while compiling: CREATE VIEW audio_meta AS SELECT _id,_data,_display_name,_size,mime_type,date_added,is_drm,date_modified,title,title_key,duration,artist_id,composer,album_id,track,year,is_ringtone,is_music,is_alarm,is_notification,is_podcast,is_doorbell,is_auto_alarm,bookmark,album_artist,drm_content_uri,drm_offset,drm_dataLen,drm_rights_issuer,drm_content_name,drm_content_description,drm_content_vendor,drm_icon_uri,drm_method,title_pinyin_key FROM files WHERE media_type=2;
03-01 09:31:24.367: E/AndroidRuntime(1065): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
03-01 09:31:24.367: E/AndroidRuntime(1065): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:893)
03-01 09:31:24.367: E/AndroidRuntime(1065): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:504)
03-01 09:31:24.367: E/AndroidRuntime(1065): at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
03-01 09:31:24.367: E/AndroidRuntime(1065): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
03-01 09:31:24.367: E/AndroidRuntime(1065): at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
03-01 09:31:24.367: E/AndroidRuntime(1065): at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1697)
03-01 09:31:24.367: E/AndroidRuntime(1065): at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1628)
03-01 09:31:24.367: E/AndroidRuntime(1065): at com.android.providers.media.MediaProvider.updateViewAfterNewTable(MediaProvider.java:7404)
03-01 09:31:24.367: E/AndroidRuntime(1065): at com.android.providers.media.MediaProvider.updateDatabase(MediaProvider.java:2264)
03-01 09:31:24.367: E/AndroidRuntime(1065): at com.android.providers.media.MediaProvider.access$1200(MediaProvider.java:126)
03-01 09:31:24.367: E/AndroidRuntime(1065): at com.android.providers.media.MediaProvider$DatabaseHelper.onCreate(MediaProvider.java:493)
03-01 09:31:24.367: E/AndroidRuntime(1065): at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252)
03-01 09:31:24.367: E/AndroidRuntime(1065): at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:188)
03-01 09:31:24.367: E/AndroidRuntime(1065): at com.android.providers.media.MediaProvider.query(MediaProvider.java:2796)
03-01 09:31:24.367: E/AndroidRuntime(1065): at com.android.providers.media.MediaProvider.attachVolume(MediaProvider.java:6391)
03-01 09:31:24.367: E/AndroidRuntime(1065): at com.android.providers.media.MediaProvider.onCreate(MediaProvider.java:889)
03-01 09:31:24.367: E/AndroidRuntime(1065): at android.content.ContentProvider.attachInfo(ContentProvider.java:1638)
03-01 09:31:24.367: E/AndroidRuntime(1065): at android.content.ContentProvider.attachInfo(ContentProvider.java:1609)
03-01 09:31:24.367: E/AndroidRuntime(1065): at android.app.ActivityThread.installProvider(ActivityThread.java:5008)
好吧,说files里没有字段“is_upload”,这是为什么呢?反复看了updateDatabase()的代码,发现有这么一段:
db.execSQL("INSERT OR REPLACE INTO files2 SELECT " + getAllColumns() + " FROM files;");
db.execSQL("DROP TABLE files;");
db.execSQL("ALTER TABLE files2 RENAME TO files;");
原来,files的源头是files2,那么在files2创建的时候加入“is_upload”字段,并且在getAllColumns()里加入该字段,即可。
编译验证,OK!
android源码中,在系统多媒体数据库中增加一个字段的更多相关文章
- Android源码笔记——Camera系统架构
Camera的架构与Android系统的整体架构保持一致,如下图所示,本文主要从以下四个方面对其进行说明. Framework:Camera.java Android Runtime:android_ ...
- Android源码阅读技巧--查找开发者选项中显示触摸操作源码
在开发者模式下,在开发者选项中,可以勾选“显示触摸操作”,然后只要点击屏幕就会在点击的位置有圈圈显示.如何找到绘制圈圈的代码部分,有什么技巧来阅读代码量这么大的android系统源码呢?以下请跟着小老 ...
- Android源码下载并绑定到Eclipse中
在Windows下,通过SDK Manager.exe更新下载的Android,是不带源码的,我们开发开发起来不是很方便: 其实Android的源代码是可以下载的,其源代码入在http://andro ...
- Android源码——Logger日志系统
Android的Logger日志系统是基于内核中的Logger日志驱动程序实现的. 日志保存在内核空间中 缓冲区保存日志 分类方法:日志的类型 + 日志的输出量 日志类型: main ...
- 将Android源码导入eclipse中的方法以及编译Android源码指定模块
本文博客地址:http://blog.csdn.net/qq1084283172/article/details/53365659 将android源码导入eclipse.androidstudio. ...
- wubi安装ubuntu后,增加swap大小,优化swap的使用参数-----------让ubuntu健步如飞,为编译android源码准备
wubi安装ubuntu后,终端输入free -m可以查到如下信息: total used free shared buffers cached Mem: 1944 1801 143 0 557 70 ...
- 编译android源码m、mm、mmm命令的使用
http://blog.163.com/zz_forward/blog/static/212898222201442873435471/ gcc怎么查看它的默认include路径和库的路径呢? //- ...
- 深入浅出 - Android系统移植与平台开发(五)- 编译Android源码(转)
2.3编译Android源码 Android源码体积非常庞大,由Dalvik虚拟机.Linux内核.编译系统.框架代码.Android定制C库.测试套件.系统应用程序等部分组成,在编译Android源 ...
- 访何红辉:谈谈Android源码中的设计模式
最近Android 6.0版本的源代码开放下载,刚好分析Android源码的技术书籍<Android源码设计模式解析与实战>上市,我们邀请到它的作者何红辉,来谈谈Android源码中的设计 ...
随机推荐
- 如何计算合适的InnoDB的(innodb_log_file_size)日志文件大小
在mysql工具中如phpmyadmin中执行show engine innodb status;注意观察Log sequence number 60秒后再次执行 获取Log sequence num ...
- test hypertext links for validity, accessibility, and recent modification
https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html The HEAD method is identical to GET except th ...
- P1220 关路灯
#include <bits/stdc++.h> using namespace std; int d[100], w[100], s, n; int dp[100][100][3]; i ...
- mysql实现分组和组内序号
SELECT CASE WHEN @mid = t.PAY_TIME THEN ELSE END SEQ, @mid := t.PAY_TIME, t.AMOUNTS, t.CHARGE_PRICE, ...
- https://blog.helong.info/blog/2015/03/13/jump_consistent_hash/
转载请说明出处:http://blog.csdn.net/cywosp/article/details/23397179 一致性哈希算法在1997年由麻省理工学院提出的一种分布式哈希(DHT) ...
- NSInternalInconsistencyException
2016-09-10 12:48:13.281 Friend[92304:1843372] *** Terminating app due to uncaught exception 'NSInter ...
- 怎样使java程序减少内存占用(转载)
本文收集网上关于减少java程序占用的一些小知识点 (1)别用new Boolean(). 在很多场景中Boolean类型是必须的,比如JDBC中boolean类型的set与get都是通过Boolea ...
- Windows Server 2008 R2 主域控制器委派DNS到子域控控制器
一.实验网络拓扑图: 二.实现目的: 子域控制器的域用户能查询到主域控制器的DNS服务器的A记录,主域控制器的域用户也能查询到子域控制器的DNS服务器的A记录. 标注:此章节不讲解域控和DNS服务器的 ...
- pip install 安装python-requests
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple python-requests
- charles抓包工具的中文乱码解决方法
charles是 MAC上最好用的抓包工具.charles 网上的参考文档已经很多,我就不再赘述啦.只是说说我在安装过程遇到的问题和解决方法,仅供参考. charles抓包的数据中的中文内容显示乱码, ...