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"  # 携带参数:删除条件
相关推荐
茉莉玫瑰花茶17 分钟前
综合案例 - AI 智能租房助手 [ 5 ]
服务器·数据库·人工智能·python·ai
ywl47081208718 分钟前
jwt生产token,简单版helloworld
java·数据库·spring
器灵科技31 分钟前
AI视频工具实测:Seedance/可灵/HappyHorse谁最能打?
java·运维·数据库·人工智能·github
BreezeDove35 分钟前
【Android】AS项目自动连接mumu模拟器配置
android
huangdong_1 小时前
京东商品图片视频批量下载与m3u8视频合并技术完整实现方案
大数据·前端·数据库
倒流时光三十年1 小时前
PostgreSQL CASE 条件表达式详解
数据库·postgresql
字节跳动数据平台1 小时前
营销视频进入工业化时代,火山引擎多模态数据湖如何助力多米实现内容生产提效 100+ 倍
数据库
健康平安的活着2 小时前
mysql中数据库脚本太大,通过脚本命令修改db名称
数据库·mysql
倒流时光三十年2 小时前
PostgreSQL COALESCE 条件表达式函数详解
数据库·postgresql
让我上个超影吧2 小时前
Claude code:Hooks
java·数据库·ai编程