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"  # 携带参数:删除条件
相关推荐
初願致夕霞几秒前
五种IO模型(详解非阻塞IO与多路转接)
linux·前端·网络·数据库·tcp/ip
脚踏实地,坚持不懈!12 分钟前
Android ANR 内核底层全解析:从一次触摸到“应用无响应”
android·linux
风哥2号13 分钟前
华为高斯数据库恢复工具FGOGDU(FGEDU openGauss DUL)
数据库·opengauss·华为高斯
小蒜学长21 分钟前
springboot党建云课堂学习与管理系统(代码+数据库+LW)
java·数据库·spring boot·后端·学习
2601_9621803321 分钟前
FlinkCDC 实现 MySQL 数据变更实时同步
数据库·mysql
2601_9621896025 分钟前
深入浅出MySQL:概述与体系结构解析
数据库·mysql
Gain_chance31 分钟前
大数据毕业设计实战|Data Insight Platform:用 FastAPI + ClickHouse 打造低门槛全链路数据洞察平台
大数据·数据库·clickhouse·毕业设计·fastapi
xhBruce32 分钟前
强制使用桌面模式 - SECONDARY_HOME -android-15.0.0_r23
android·launcher3
harmony&1 小时前
ETCD 存储系统实战:从单节点部署到 Kubernetes 高可用集群
数据库·kubernetes·etcd
2601_962066491 小时前
【玩转全栈】----Django模板的继承
数据库·django·sqlite