web-dev-qa-db-fra.com

Requête Android fournisseur de contenu à partir de la ligne de commande (adb Shell)

Il existe une commande pour démarrer une activité en fonction de l'intention: am start. Aussi pour envoyer une diffusion: am broadcast.

Je pense qu'il devrait probablement y avoir une commande Shell pour interroger un fournisseur de contenu, probablement quelque chose comme:

query content://com.myapp.authority/path --where 'column=?' --arg 1 --order 'column desc'

ou similaire.

Est-ce qu'il y a un?

21

Il existe une commande content:

usage: adb Shell content [subcommand] [options]

usage: adb Shell content insert --uri <URI> [--user <USER_ID>] --bind <BINDING> [--bind <BINDING>...]
  <URI> a content provider URI.
  <BINDING> binds a typed value to a column and is formatted:
  <COLUMN_NAME>:<TYPE>:<COLUMN_VALUE> where:
  <TYPE> specifies data type such as:
  b - boolean, s - string, i - integer, l - long, f - float, d - double
  Note: Omit the value for passing an empty string, e.g column:s:
  Example:
  # Add "new_setting" secure setting with value "new_value".
  adb Shell content insert --uri content://settings/secure --bind name:s:new_setting --bind value:s:new_value

usage: adb Shell content update --uri <URI> [--user <USER_ID>] [--where <WHERE>]
  <WHERE> is a SQL style where clause in quotes (You have to escape single quotes - see example below).
  Example:
  # Change "new_setting" secure setting to "newer_value".
  adb Shell content update --uri content://settings/secure --bind value:s:newer_value --where "name='new_setting'"

usage: adb Shell content delete --uri <URI> [--user <USER_ID>] --bind <BINDING> [--bind <BINDING>...] [--where <WHERE>]
  Example:
  # Remove "new_setting" secure setting.
  adb Shell content delete --uri content://settings/secure --where "name='new_setting'"

usage: adb Shell content query --uri <URI> [--user <USER_ID>] [--projection <PROJECTION>] [--where <WHERE>] [--sort <SORT_ORDER>]
  <PROJECTION> is a list of colon separated column names and is formatted:
  <COLUMN_NAME>[:<COLUMN_NAME>...]
  <SORT_ORDER> is the order in which rows in the result should be sorted.
  Example:
  # Select "name" and "value" columns from secure settings where "name" is equal to "new_setting" and sort the result by name in ascending order.
  adb Shell content query --uri content://settings/secure --projection name:value --where "name='new_setting'" --sort "name ASC"

usage: adb Shell content call --uri <URI> --method <METHOD> [--arg <ARG>]
       [--extra <BINDING> ...]
  <METHOD> is the name of a provider-defined method
  <ARG> is an optional string argument
  <BINDING> is like --bind above, typed data of the form <KEY>:{b,s,i,l,f,d}:<VAL>
38
Alex P.