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"  # 携带参数:删除条件
相关推荐
砖厂小工2 小时前
用 GLM + OpenClaw 打造你的 AI PR Review Agent — 让龙虾帮你审代码
android·github
全栈老石2 小时前
拆解低代码引擎核心:元数据驱动的"万能表"架构
数据库·低代码
张拭心3 小时前
春节后,有些公司明确要求 AI 经验了
android·前端·人工智能
张拭心3 小时前
Android 17 来了!新特性介绍与适配建议
android·前端
Kapaseker5 小时前
Compose 进阶—巧用 GraphicsLayer
android·kotlin
黄林晴6 小时前
Android17 为什么重写 MessageQueue
android
倔强的石头_21 小时前
kingbase备份与恢复实战(二)—— sys_dump库级逻辑备份与恢复(Windows详细步骤)
数据库
阿巴斯甜1 天前
Android 报错:Zip file '/Users/lyy/develop/repoAndroidLapp/l-app-android-ble/app/bu
android
Kapaseker1 天前
实战 Compose 中的 IntrinsicSize
android·kotlin
xq95271 天前
Andorid Google 登录接入文档
android