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"  # 携带参数:删除条件
相关推荐
我是场3 小时前
Android Camera 从应用到硬件之- 枚举Camera - 1
android
4Forsee3 小时前
【Android】View 事件分发机制与源码解析
android·java·前端
咕噜签名分发冰淇淋3 小时前
苹果ios安卓apk应用APP文件怎么修改手机APP显示的名称
android·ios·智能手机
Pluchon3 小时前
硅基计划5.0 MySQL 陆 视图&JDBC编程&用户权限控制
数据库·mysql·1024程序员节
应用市场3 小时前
从零开始打造Android桌面Launcher应用:原理剖析与完整实现
android
叶羽西3 小时前
Android15增强型视觉系统(EVS)
android
沅霖3 小时前
android kotlin语言中的协程
android·开发语言·kotlin
摇滚侠3 小时前
Spring Boot3零基础教程,自定义 starter,把项目封装成依赖给别人使用,笔记65
数据库·spring boot·笔记
不剪发的Tony老师3 小时前
SQLiteSpy:一款轻量级的SQLite管理工具
数据库·sqlite