Android ContentProvier

ADB 调试

通过adb调试应该是最简单的场景。

adb shell content query --uri content://com.xxx.xxx.xxx/xxx/123

下面是常见操作的参考

adb shell content <操作> --uri <ContentProvider的Uri> 参数

列出设备上所有可用的 ContentProvider

复制代码
adb shell dumpsys package providers

输出中包含所有 ContentProviderauthority、权限、进程等信息,可用于确认目标 Uri 是否正确。

过滤特定应用的 ContentProvider

复制代码
adb shell dumpsys package providers | grep "com.example.channelprovider"

查询数据(query)

通过Uri 中携带路径参数

bash 复制代码
adb shell content query --uri content://com.example.provider/channel/100  # 100 是路径参数

获取所有数据:

复制代码
adb shell content query --uri content://com.example.channelprovider/channel

指定查询列(--projection):

复制代码
adb shell content query --uri content://com.example.channelprovider/channel \
  --projection "_id,channel_name,channel_num"

添加查询条件【selection】(--where):

在adb 测试中,需要静态指定参数selection 。不可使用selectionArgs

复制代码
adb shell content query --uri content://com.example.channelprovider/channel \
  --projection "channel_name,channel_num" \
  --where "channel_num > 50"

按条件排序【sortOrder】(--sort):

复制代码
adb shell content query --uri content://com.example.channelprovider/channel \
  --sort "channel_num ASC"
2. 插入数据(insert)

通过 --bind 指定字段值(格式:字段名:类型:值,类型可选 s字符串 /i整数 /l长整数等):

复制代码
adb shell content insert --uri content://com.example.channelprovider/channel \
  --bind "channel_name:s:测试频道" \
  --bind "channel_num:i:100" \
  --bind "intent:s:intent://test#Intent;end"
3. 更新数据(update)
复制代码
adb shell content update --uri content://com.example.channelprovider/channel \
  --bind "channel_name:s:更新后的测试频道" \
  --where "channel_num = 100"
示例:更新带参数的数据

channel_num=20 的频道名称改为 "NBA 篮球频道",携带参数:

复制代码
adb shell content update \
  --uri content://com.example.channelprovider/channel \
  --bind "channel_name:s:NBA篮球频道" \  # 携带参数:要更新的字段值
  --where "channel_num = 20"            # 携带参数:更新条件
4. 删除数据(delete)
复制代码
adb shell content delete --uri content://com.example.channelprovider/channel \
  --where "channel_num = 100"
示例:删除带参数的数据

删除 channel_num < 10 的频道,携带条件参数:

复制代码
adb shell content delete \
  --uri content://com.example.channelprovider/channel \
  --where "channel_num < 10"  # 携带参数:删除条件
相关推荐
壮哥_icon16 小时前
【Android 系统开发】使用 BAT 脚本高效自动化管理 /system/priv-app/ 系统应用(安装与卸载)
android·运维·自动化
Database_Cool_17 小时前
AI Agent 长期记忆怎么存?阿里云 PolarDB-X 对接 Mem0 记忆框架实践
数据库·阿里云
会编程的土豆17 小时前
数据库范式
数据库·oracle
L16247617 小时前
MySQL 全环境生产快速安装 + 完整配置手册(整合国产银河麒麟适配 + 主从补充版)
数据库·mysql
yio_yin17 小时前
Spring事务管理(数据一致性)
数据库·sql·spring
X Chow17 小时前
MongoDB Beginner Guide 01:理解 NoSQL、文档模型与 Python 开发环境
数据库·mongodb·nosql
用户693717500138417 小时前
Claude Code终端日志Token占用实测:一个过滤器砍掉60%-90%
android·前端·后端
蝉蜕日记18 小时前
AccumuPDF高级版 v2.57 | 视图文转换PDF,合并分割压缩
android·智能手机·pdf·生活·软件需求
前端世界18 小时前
MySQL 基础入门(学习第4天)——约束与 DML 操作详解
数据库·学习·mysql
吐了啊取名字太难18 小时前
美颜系统AI修图本地跑并支持Mac、win、安卓、iOS不卡顿
android·人工智能·windows·数码相机·mac·ai编程