MediaStore.java revision 2f189fa0f75d6899b9fa7db11f5301bc7850b744
1/* 2 * Copyright (C) 2007 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.provider; 18 19import android.annotation.SdkConstant; 20import android.annotation.SdkConstant.SdkConstantType; 21import android.content.ContentResolver; 22import android.content.ContentValues; 23import android.content.ContentUris; 24import android.database.Cursor; 25import android.database.DatabaseUtils; 26import android.graphics.Bitmap; 27import android.graphics.BitmapFactory; 28import android.graphics.Matrix; 29import android.net.Uri; 30import android.os.Environment; 31import android.util.Log; 32 33import java.io.FileInputStream; 34import java.io.FileNotFoundException; 35import java.io.IOException; 36import java.io.InputStream; 37import java.io.OutputStream; 38import java.io.UnsupportedEncodingException; 39import java.text.Collator; 40 41/** 42 * The Media provider contains meta data for all available media on both internal 43 * and external storage devices. 44 */ 45public final class MediaStore 46{ 47 private final static String TAG = "MediaStore"; 48 49 public static final String AUTHORITY = "media"; 50 51 private static final String CONTENT_AUTHORITY_SLASH = "content://" + AUTHORITY + "/"; 52 53 /** 54 * Activity Action: Perform a search for media. 55 * Contains at least the {@link android.app.SearchManager#QUERY} extra. 56 * May also contain any combination of the following extras: 57 * EXTRA_MEDIA_ARTIST, EXTRA_MEDIA_ALBUM, EXTRA_MEDIA_TITLE, EXTRA_MEDIA_FOCUS 58 * 59 * @see android.provider.MediaStore#EXTRA_MEDIA_ARTIST 60 * @see android.provider.MediaStore#EXTRA_MEDIA_ALBUM 61 * @see android.provider.MediaStore#EXTRA_MEDIA_TITLE 62 * @see android.provider.MediaStore#EXTRA_MEDIA_FOCUS 63 */ 64 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) 65 public static final String INTENT_ACTION_MEDIA_SEARCH = "android.intent.action.MEDIA_SEARCH"; 66 67 /** 68 * The name of the Intent-extra used to define the artist 69 */ 70 public static final String EXTRA_MEDIA_ARTIST = "android.intent.extra.artist"; 71 /** 72 * The name of the Intent-extra used to define the album 73 */ 74 public static final String EXTRA_MEDIA_ALBUM = "android.intent.extra.album"; 75 /** 76 * The name of the Intent-extra used to define the song title 77 */ 78 public static final String EXTRA_MEDIA_TITLE = "android.intent.extra.title"; 79 /** 80 * The name of the Intent-extra used to define the search focus. The search focus 81 * indicates whether the search should be for things related to the artist, album 82 * or song that is identified by the other extras. 83 */ 84 public static final String EXTRA_MEDIA_FOCUS = "android.intent.extra.focus"; 85 86 /** 87 * The name of the Intent-extra used to control the orientation of a ViewImage or a MovieView. 88 * This is an int property that overrides the activity's requestedOrientation. 89 * @see android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED 90 */ 91 public static final String EXTRA_SCREEN_ORIENTATION = "android.intent.extra.screenOrientation"; 92 93 /** 94 * The name of an Intent-extra used to control the UI of a ViewImage. 95 * This is a boolean property that overrides the activity's default fullscreen state. 96 * @hide 97 */ 98 public static final String EXTRA_FULL_SCREEN = "android.intent.extra.fullScreen"; 99 100 /** 101 * The name of an Intent-extra used to control the UI of a ViewImage. 102 * This is a boolean property that specifies whether or not to show action icons. 103 * @hide 104 */ 105 public static final String EXTRA_SHOW_ACTION_ICONS = "android.intent.extra.showActionIcons"; 106 107 /** 108 * The name of the Intent-extra used to control the onCompletion behavior of a MovieView. 109 * This is a boolean property that specifies whether or not to finish the MovieView activity 110 * when the movie completes playing. The default value is true, which means to automatically 111 * exit the movie player activity when the movie completes playing. 112 */ 113 public static final String EXTRA_FINISH_ON_COMPLETION = "android.intent.extra.finishOnCompletion"; 114 115 /** 116 * The name of the Intent action used to launch a camera in still image mode. 117 */ 118 public static final String INTENT_ACTION_STILL_IMAGE_CAMERA = "android.media.action.STILL_IMAGE_CAMERA"; 119 120 /** 121 * The name of the Intent action used to launch a camera in video mode. 122 */ 123 public static final String INTENT_ACTION_VIDEO_CAMERA = "android.media.action.VIDEO_CAMERA"; 124 125 /** 126 * Standard Intent action that can be sent to have the camera application 127 * capture an image and return it. 128 * <p> 129 * The caller may pass an extra EXTRA_OUTPUT to control where this image will be written. 130 * If the EXTRA_OUTPUT is not present, then a small sized image is returned as a Bitmap 131 * object in the extra field. This is useful for applications that only need a small image. 132 * If the EXTRA_OUTPUT is present, then the full-sized image will be written to the Uri 133 * value of EXTRA_OUTPUT. 134 * @see #EXTRA_OUTPUT 135 * @see #EXTRA_VIDEO_QUALITY 136 */ 137 public final static String ACTION_IMAGE_CAPTURE = "android.media.action.IMAGE_CAPTURE"; 138 139 /** 140 * Standard Intent action that can be sent to have the camera application 141 * capture an video and return it. 142 * <p> 143 * The caller may pass in an extra EXTRA_VIDEO_QUALITY to control the video quality. 144 * <p> 145 * The caller may pass in an extra EXTRA_OUTPUT to control 146 * where the video is written. If EXTRA_OUTPUT is not present the video will be 147 * written to the standard location for videos, and the Uri of that location will be 148 * returned in the data field of the Uri. 149 * @see #EXTRA_OUTPUT 150 */ 151 public final static String ACTION_VIDEO_CAPTURE = "android.media.action.VIDEO_CAPTURE"; 152 153 /** 154 * The name of the Intent-extra used to control the quality of a recorded video. This is an 155 * integer property. Currently value 0 means low quality, suitable for MMS messages, and 156 * value 1 means high quality. In the future other quality levels may be added. 157 */ 158 public final static String EXTRA_VIDEO_QUALITY = "android.intent.extra.videoQuality"; 159 160 /** 161 * Specify the maximum allowed size. 162 * @hide 163 */ 164 public final static String EXTRA_SIZE_LIMIT = "android.intent.extra.sizeLimit"; 165 166 /** 167 * The name of the Intent-extra used to indicate a content resolver Uri to be used to 168 * store the requested image or video. 169 */ 170 public final static String EXTRA_OUTPUT = "output"; 171 172 /** 173 * Common fields for most MediaProvider tables 174 */ 175 176 public interface MediaColumns extends BaseColumns { 177 /** 178 * The data stream for the file 179 * <P>Type: DATA STREAM</P> 180 */ 181 public static final String DATA = "_data"; 182 183 /** 184 * The size of the file in bytes 185 * <P>Type: INTEGER (long)</P> 186 */ 187 public static final String SIZE = "_size"; 188 189 /** 190 * The display name of the file 191 * <P>Type: TEXT</P> 192 */ 193 public static final String DISPLAY_NAME = "_display_name"; 194 195 /** 196 * The title of the content 197 * <P>Type: TEXT</P> 198 */ 199 public static final String TITLE = "title"; 200 201 /** 202 * The time the file was added to the media provider 203 * Units are seconds since 1970. 204 * <P>Type: INTEGER (long)</P> 205 */ 206 public static final String DATE_ADDED = "date_added"; 207 208 /** 209 * The time the file was last modified 210 * Units are seconds since 1970. 211 * NOTE: This is for internal use by the media scanner. Do not modify this field. 212 * <P>Type: INTEGER (long)</P> 213 */ 214 public static final String DATE_MODIFIED = "date_modified"; 215 216 /** 217 * The MIME type of the file 218 * <P>Type: TEXT</P> 219 */ 220 public static final String MIME_TYPE = "mime_type"; 221 } 222 223 /** 224 * Contains meta data for all available images. 225 */ 226 public static final class Images 227 { 228 public interface ImageColumns extends MediaColumns { 229 /** 230 * The description of the image 231 * <P>Type: TEXT</P> 232 */ 233 public static final String DESCRIPTION = "description"; 234 235 /** 236 * The picasa id of the image 237 * <P>Type: TEXT</P> 238 */ 239 public static final String PICASA_ID = "picasa_id"; 240 241 /** 242 * Whether the video should be published as public or private 243 * <P>Type: INTEGER</P> 244 */ 245 public static final String IS_PRIVATE = "isprivate"; 246 247 /** 248 * The latitude where the image was captured. 249 * <P>Type: DOUBLE</P> 250 */ 251 public static final String LATITUDE = "latitude"; 252 253 /** 254 * The longitude where the image was captured. 255 * <P>Type: DOUBLE</P> 256 */ 257 public static final String LONGITUDE = "longitude"; 258 259 /** 260 * The date & time that the image was taken in units 261 * of milliseconds since jan 1, 1970. 262 * <P>Type: INTEGER</P> 263 */ 264 public static final String DATE_TAKEN = "datetaken"; 265 266 /** 267 * The orientation for the image expressed as degrees. 268 * Only degrees 0, 90, 180, 270 will work. 269 * <P>Type: INTEGER</P> 270 */ 271 public static final String ORIENTATION = "orientation"; 272 273 /** 274 * The mini thumb id. 275 * <P>Type: INTEGER</P> 276 */ 277 public static final String MINI_THUMB_MAGIC = "mini_thumb_magic"; 278 279 /** 280 * The bucket id of the image. This is a read-only property that 281 * is automatically computed from the DATA column. 282 * <P>Type: TEXT</P> 283 */ 284 public static final String BUCKET_ID = "bucket_id"; 285 286 /** 287 * The bucket display name of the image. This is a read-only property that 288 * is automatically computed from the DATA column. 289 * <P>Type: TEXT</P> 290 */ 291 public static final String BUCKET_DISPLAY_NAME = "bucket_display_name"; 292 } 293 294 public static final class Media implements ImageColumns { 295 public static final Cursor query(ContentResolver cr, Uri uri, String[] projection) 296 { 297 return cr.query(uri, projection, null, null, DEFAULT_SORT_ORDER); 298 } 299 300 public static final Cursor query(ContentResolver cr, Uri uri, String[] projection, 301 String where, String orderBy) 302 { 303 return cr.query(uri, projection, where, 304 null, orderBy == null ? DEFAULT_SORT_ORDER : orderBy); 305 } 306 307 public static final Cursor query(ContentResolver cr, Uri uri, String[] projection, 308 String selection, String [] selectionArgs, String orderBy) 309 { 310 return cr.query(uri, projection, selection, 311 selectionArgs, orderBy == null ? DEFAULT_SORT_ORDER : orderBy); 312 } 313 314 /** 315 * Retrieves an image for the given url as a {@link Bitmap}. 316 * 317 * @param cr The content resolver to use 318 * @param url The url of the image 319 * @throws FileNotFoundException 320 * @throws IOException 321 */ 322 public static final Bitmap getBitmap(ContentResolver cr, Uri url) 323 throws FileNotFoundException, IOException 324 { 325 InputStream input = cr.openInputStream(url); 326 Bitmap bitmap = BitmapFactory.decodeStream(input); 327 input.close(); 328 return bitmap; 329 } 330 331 /** 332 * Insert an image and create a thumbnail for it. 333 * 334 * @param cr The content resolver to use 335 * @param imagePath The path to the image to insert 336 * @param name The name of the image 337 * @param description The description of the image 338 * @return The URL to the newly created image 339 * @throws FileNotFoundException 340 */ 341 public static final String insertImage(ContentResolver cr, String imagePath, String name, 342 String description) throws FileNotFoundException 343 { 344 // Check if file exists with a FileInputStream 345 FileInputStream stream = new FileInputStream(imagePath); 346 try { 347 Bitmap bm = BitmapFactory.decodeFile(imagePath); 348 String ret = insertImage(cr, bm, name, description); 349 bm.recycle(); 350 return ret; 351 } finally { 352 try { 353 stream.close(); 354 } catch (IOException e) { 355 } 356 } 357 } 358 359 private static final Bitmap StoreThumbnail( 360 ContentResolver cr, 361 Bitmap source, 362 long id, 363 float width, float height, 364 int kind) { 365 // create the matrix to scale it 366 Matrix matrix = new Matrix(); 367 368 float scaleX = width / source.getWidth(); 369 float scaleY = height / source.getHeight(); 370 371 matrix.setScale(scaleX, scaleY); 372 373 Bitmap thumb = Bitmap.createBitmap(source, 0, 0, 374 source.getWidth(), 375 source.getHeight(), matrix, 376 true); 377 378 ContentValues values = new ContentValues(4); 379 values.put(Images.Thumbnails.KIND, kind); 380 values.put(Images.Thumbnails.IMAGE_ID, (int)id); 381 values.put(Images.Thumbnails.HEIGHT, thumb.getHeight()); 382 values.put(Images.Thumbnails.WIDTH, thumb.getWidth()); 383 384 Uri url = cr.insert(Images.Thumbnails.EXTERNAL_CONTENT_URI, values); 385 386 try { 387 OutputStream thumbOut = cr.openOutputStream(url); 388 389 thumb.compress(Bitmap.CompressFormat.JPEG, 100, thumbOut); 390 thumbOut.close(); 391 return thumb; 392 } 393 catch (FileNotFoundException ex) { 394 return null; 395 } 396 catch (IOException ex) { 397 return null; 398 } 399 } 400 401 /** 402 * Insert an image and create a thumbnail for it. 403 * 404 * @param cr The content resolver to use 405 * @param source The stream to use for the image 406 * @param title The name of the image 407 * @param description The description of the image 408 * @return The URL to the newly created image, or <code>null</code> if the image failed to be stored 409 * for any reason. 410 */ 411 public static final String insertImage(ContentResolver cr, Bitmap source, 412 String title, String description) 413 { 414 ContentValues values = new ContentValues(); 415 values.put(Images.Media.TITLE, title); 416 values.put(Images.Media.DESCRIPTION, description); 417 values.put(Images.Media.MIME_TYPE, "image/jpeg"); 418 419 Uri url = null; 420 String stringUrl = null; /* value to be returned */ 421 422 try 423 { 424 url = cr.insert(EXTERNAL_CONTENT_URI, values); 425 426 if (source != null) { 427 OutputStream imageOut = cr.openOutputStream(url); 428 try { 429 source.compress(Bitmap.CompressFormat.JPEG, 50, imageOut); 430 } finally { 431 imageOut.close(); 432 } 433 434 long id = ContentUris.parseId(url); 435 Bitmap miniThumb = StoreThumbnail(cr, source, id, 320F, 240F, Images.Thumbnails.MINI_KIND); 436 Bitmap microThumb = StoreThumbnail(cr, miniThumb, id, 50F, 50F, Images.Thumbnails.MICRO_KIND); 437 } else { 438 Log.e(TAG, "Failed to create thumbnail, removing original"); 439 cr.delete(url, null, null); 440 url = null; 441 } 442 } catch (Exception e) { 443 Log.e(TAG, "Failed to insert image", e); 444 if (url != null) { 445 cr.delete(url, null, null); 446 url = null; 447 } 448 } 449 450 if (url != null) { 451 stringUrl = url.toString(); 452 } 453 454 return stringUrl; 455 } 456 457 /** 458 * Get the content:// style URI for the image media table on the 459 * given volume. 460 * 461 * @param volumeName the name of the volume to get the URI for 462 * @return the URI to the image media table on the given volume 463 */ 464 public static Uri getContentUri(String volumeName) { 465 return Uri.parse(CONTENT_AUTHORITY_SLASH + volumeName + 466 "/images/media"); 467 } 468 469 /** 470 * The content:// style URI for the internal storage. 471 */ 472 public static final Uri INTERNAL_CONTENT_URI = 473 getContentUri("internal"); 474 475 /** 476 * The content:// style URI for the "primary" external storage 477 * volume. 478 */ 479 public static final Uri EXTERNAL_CONTENT_URI = 480 getContentUri("external"); 481 482 /** 483 * The MIME type of of this directory of 484 * images. Note that each entry in this directory will have a standard 485 * image MIME type as appropriate -- for example, image/jpeg. 486 */ 487 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/image"; 488 489 /** 490 * The default sort order for this table 491 */ 492 public static final String DEFAULT_SORT_ORDER = ImageColumns.BUCKET_DISPLAY_NAME; 493 } 494 495 public static class Thumbnails implements BaseColumns 496 { 497 public static final Cursor query(ContentResolver cr, Uri uri, String[] projection) 498 { 499 return cr.query(uri, projection, null, null, DEFAULT_SORT_ORDER); 500 } 501 502 public static final Cursor queryMiniThumbnails(ContentResolver cr, Uri uri, int kind, String[] projection) 503 { 504 return cr.query(uri, projection, "kind = " + kind, null, DEFAULT_SORT_ORDER); 505 } 506 507 public static final Cursor queryMiniThumbnail(ContentResolver cr, long origId, int kind, String[] projection) 508 { 509 return cr.query(EXTERNAL_CONTENT_URI, projection, 510 IMAGE_ID + " = " + origId + " AND " + KIND + " = " + 511 kind, null, null); 512 } 513 514 /** 515 * Get the content:// style URI for the image media table on the 516 * given volume. 517 * 518 * @param volumeName the name of the volume to get the URI for 519 * @return the URI to the image media table on the given volume 520 */ 521 public static Uri getContentUri(String volumeName) { 522 return Uri.parse(CONTENT_AUTHORITY_SLASH + volumeName + 523 "/images/thumbnails"); 524 } 525 526 /** 527 * The content:// style URI for the internal storage. 528 */ 529 public static final Uri INTERNAL_CONTENT_URI = 530 getContentUri("internal"); 531 532 /** 533 * The content:// style URI for the "primary" external storage 534 * volume. 535 */ 536 public static final Uri EXTERNAL_CONTENT_URI = 537 getContentUri("external"); 538 539 /** 540 * The default sort order for this table 541 */ 542 public static final String DEFAULT_SORT_ORDER = "image_id ASC"; 543 544 /** 545 * The data stream for the thumbnail 546 * <P>Type: DATA STREAM</P> 547 */ 548 public static final String DATA = "_data"; 549 550 /** 551 * The original image for the thumbnal 552 * <P>Type: INTEGER (ID from Images table)</P> 553 */ 554 public static final String IMAGE_ID = "image_id"; 555 556 /** 557 * The kind of the thumbnail 558 * <P>Type: INTEGER (One of the values below)</P> 559 */ 560 public static final String KIND = "kind"; 561 562 public static final int MINI_KIND = 1; 563 public static final int FULL_SCREEN_KIND = 2; 564 public static final int MICRO_KIND = 3; 565 566 /** 567 * The width of the thumbnal 568 * <P>Type: INTEGER (long)</P> 569 */ 570 public static final String WIDTH = "width"; 571 572 /** 573 * The height of the thumbnail 574 * <P>Type: INTEGER (long)</P> 575 */ 576 public static final String HEIGHT = "height"; 577 } 578 } 579 580 /** 581 * Container for all audio content. 582 */ 583 public static final class Audio { 584 /** 585 * Columns for audio file that show up in multiple tables. 586 */ 587 public interface AudioColumns extends MediaColumns { 588 589 /** 590 * A non human readable key calculated from the TITLE, used for 591 * searching, sorting and grouping 592 * <P>Type: TEXT</P> 593 */ 594 public static final String TITLE_KEY = "title_key"; 595 596 /** 597 * The duration of the audio file, in ms 598 * <P>Type: INTEGER (long)</P> 599 */ 600 public static final String DURATION = "duration"; 601 602 /** 603 * The position, in ms, playback was at when playback for this file 604 * was last stopped. 605 * <P>Type: INTEGER (long)</P> 606 * @hide 607 */ 608 public static final String BOOKMARK = "bookmark"; 609 610 /** 611 * The id of the artist who created the audio file, if any 612 * <P>Type: INTEGER (long)</P> 613 */ 614 public static final String ARTIST_ID = "artist_id"; 615 616 /** 617 * The artist who created the audio file, if any 618 * <P>Type: TEXT</P> 619 */ 620 public static final String ARTIST = "artist"; 621 622 /** 623 * A non human readable key calculated from the ARTIST, used for 624 * searching, sorting and grouping 625 * <P>Type: TEXT</P> 626 */ 627 public static final String ARTIST_KEY = "artist_key"; 628 629 /** 630 * The composer of the audio file, if any 631 * <P>Type: TEXT</P> 632 */ 633 public static final String COMPOSER = "composer"; 634 635 /** 636 * The id of the album the audio file is from, if any 637 * <P>Type: INTEGER (long)</P> 638 */ 639 public static final String ALBUM_ID = "album_id"; 640 641 /** 642 * The album the audio file is from, if any 643 * <P>Type: TEXT</P> 644 */ 645 public static final String ALBUM = "album"; 646 647 /** 648 * A non human readable key calculated from the ALBUM, used for 649 * searching, sorting and grouping 650 * <P>Type: TEXT</P> 651 */ 652 public static final String ALBUM_KEY = "album_key"; 653 654 /** 655 * A URI to the album art, if any 656 * <P>Type: TEXT</P> 657 */ 658 public static final String ALBUM_ART = "album_art"; 659 660 /** 661 * The track number of this song on the album, if any. 662 * This number encodes both the track number and the 663 * disc number. For multi-disc sets, this number will 664 * be 1xxx for tracks on the first disc, 2xxx for tracks 665 * on the second disc, etc. 666 * <P>Type: INTEGER</P> 667 */ 668 public static final String TRACK = "track"; 669 670 /** 671 * The year the audio file was recorded, if any 672 * <P>Type: INTEGER</P> 673 */ 674 public static final String YEAR = "year"; 675 676 /** 677 * Non-zero if the audio file is music 678 * <P>Type: INTEGER (boolean)</P> 679 */ 680 public static final String IS_MUSIC = "is_music"; 681 682 /** 683 * Non-zero if the audio file is a podcast 684 * <P>Type: INTEGER (boolean)</P> 685 * @hide 686 */ 687 public static final String IS_PODCAST = "is_podcast"; 688 689 /** 690 * Non-zero id the audio file may be a ringtone 691 * <P>Type: INTEGER (boolean)</P> 692 */ 693 public static final String IS_RINGTONE = "is_ringtone"; 694 695 /** 696 * Non-zero id the audio file may be an alarm 697 * <P>Type: INTEGER (boolean)</P> 698 */ 699 public static final String IS_ALARM = "is_alarm"; 700 701 /** 702 * Non-zero id the audio file may be a notification sound 703 * <P>Type: INTEGER (boolean)</P> 704 */ 705 public static final String IS_NOTIFICATION = "is_notification"; 706 } 707 708 /** 709 * Converts a name to a "key" that can be used for grouping, sorting 710 * and searching. 711 * The rules that govern this conversion are: 712 * - remove 'special' characters like ()[]'!?., 713 * - remove leading/trailing spaces 714 * - convert everything to lowercase 715 * - remove leading "the ", "an " and "a " 716 * - remove trailing ", the|an|a" 717 * - remove accents. This step leaves us with CollationKey data, 718 * which is not human readable 719 * 720 * @param name The artist or album name to convert 721 * @return The "key" for the given name. 722 */ 723 public static String keyFor(String name) { 724 if (name != null) { 725 if (name.equals(android.media.MediaFile.UNKNOWN_STRING)) { 726 return "\001"; 727 } 728 name = name.trim().toLowerCase(); 729 if (name.startsWith("the ")) { 730 name = name.substring(4); 731 } 732 if (name.startsWith("an ")) { 733 name = name.substring(3); 734 } 735 if (name.startsWith("a ")) { 736 name = name.substring(2); 737 } 738 if (name.endsWith(", the") || name.endsWith(",the") || 739 name.endsWith(", an") || name.endsWith(",an") || 740 name.endsWith(", a") || name.endsWith(",a")) { 741 name = name.substring(0, name.lastIndexOf(',')); 742 } 743 name = name.replaceAll("[\\[\\]\\(\\)\"'.,?!]", "").trim(); 744 if (name.length() > 0) { 745 // Insert a separator between the characters to avoid 746 // matches on a partial character. If we ever change 747 // to start-of-word-only matches, this can be removed. 748 StringBuilder b = new StringBuilder(); 749 b.append('.'); 750 int nl = name.length(); 751 for (int i = 0; i < nl; i++) { 752 b.append(name.charAt(i)); 753 b.append('.'); 754 } 755 name = b.toString(); 756 return DatabaseUtils.getCollationKey(name); 757 } else { 758 return ""; 759 } 760 } 761 return null; 762 } 763 764 public static final class Media implements AudioColumns { 765 /** 766 * Get the content:// style URI for the audio media table on the 767 * given volume. 768 * 769 * @param volumeName the name of the volume to get the URI for 770 * @return the URI to the audio media table on the given volume 771 */ 772 public static Uri getContentUri(String volumeName) { 773 return Uri.parse(CONTENT_AUTHORITY_SLASH + volumeName + 774 "/audio/media"); 775 } 776 777 public static Uri getContentUriForPath(String path) { 778 return (path.startsWith(Environment.getExternalStorageDirectory().getPath()) ? 779 EXTERNAL_CONTENT_URI : INTERNAL_CONTENT_URI); 780 } 781 782 /** 783 * The content:// style URI for the internal storage. 784 */ 785 public static final Uri INTERNAL_CONTENT_URI = 786 getContentUri("internal"); 787 788 /** 789 * The content:// style URI for the "primary" external storage 790 * volume. 791 */ 792 public static final Uri EXTERNAL_CONTENT_URI = 793 getContentUri("external"); 794 795 /** 796 * The MIME type for this table. 797 */ 798 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/audio"; 799 800 /** 801 * The default sort order for this table 802 */ 803 public static final String DEFAULT_SORT_ORDER = TITLE; 804 805 /** 806 * Activity Action: Start SoundRecorder application. 807 * <p>Input: nothing. 808 * <p>Output: An uri to the recorded sound stored in the Media Library 809 * if the recording was successful. 810 * May also contain the extra EXTRA_MAX_BYTES. 811 * @see #EXTRA_MAX_BYTES 812 */ 813 public static final String RECORD_SOUND_ACTION = 814 "android.provider.MediaStore.RECORD_SOUND"; 815 816 /** 817 * The name of the Intent-extra used to define a maximum file size for 818 * a recording made by the SoundRecorder application. 819 * 820 * @see #RECORD_SOUND_ACTION 821 */ 822 public static final String EXTRA_MAX_BYTES = 823 "android.provider.MediaStore.extra.MAX_BYTES"; 824 } 825 826 /** 827 * Columns representing an audio genre 828 */ 829 public interface GenresColumns { 830 /** 831 * The name of the genre 832 * <P>Type: TEXT</P> 833 */ 834 public static final String NAME = "name"; 835 } 836 837 /** 838 * Contains all genres for audio files 839 */ 840 public static final class Genres implements BaseColumns, GenresColumns { 841 /** 842 * Get the content:// style URI for the audio genres table on the 843 * given volume. 844 * 845 * @param volumeName the name of the volume to get the URI for 846 * @return the URI to the audio genres table on the given volume 847 */ 848 public static Uri getContentUri(String volumeName) { 849 return Uri.parse(CONTENT_AUTHORITY_SLASH + volumeName + 850 "/audio/genres"); 851 } 852 853 /** 854 * The content:// style URI for the internal storage. 855 */ 856 public static final Uri INTERNAL_CONTENT_URI = 857 getContentUri("internal"); 858 859 /** 860 * The content:// style URI for the "primary" external storage 861 * volume. 862 */ 863 public static final Uri EXTERNAL_CONTENT_URI = 864 getContentUri("external"); 865 866 /** 867 * The MIME type for this table. 868 */ 869 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/genre"; 870 871 /** 872 * The MIME type for entries in this table. 873 */ 874 public static final String ENTRY_CONTENT_TYPE = "vnd.android.cursor.item/genre"; 875 876 /** 877 * The default sort order for this table 878 */ 879 public static final String DEFAULT_SORT_ORDER = NAME; 880 881 /** 882 * Sub-directory of each genre containing all members. 883 */ 884 public static final class Members implements AudioColumns { 885 886 public static final Uri getContentUri(String volumeName, 887 long genreId) { 888 return Uri.parse(CONTENT_AUTHORITY_SLASH + volumeName 889 + "/audio/genres/" + genreId + "/members"); 890 } 891 892 /** 893 * A subdirectory of each genre containing all member audio files. 894 */ 895 public static final String CONTENT_DIRECTORY = "members"; 896 897 /** 898 * The default sort order for this table 899 */ 900 public static final String DEFAULT_SORT_ORDER = TITLE; 901 902 /** 903 * The ID of the audio file 904 * <P>Type: INTEGER (long)</P> 905 */ 906 public static final String AUDIO_ID = "audio_id"; 907 908 /** 909 * The ID of the genre 910 * <P>Type: INTEGER (long)</P> 911 */ 912 public static final String GENRE_ID = "genre_id"; 913 } 914 } 915 916 /** 917 * Columns representing a playlist 918 */ 919 public interface PlaylistsColumns { 920 /** 921 * The name of the playlist 922 * <P>Type: TEXT</P> 923 */ 924 public static final String NAME = "name"; 925 926 /** 927 * The data stream for the playlist file 928 * <P>Type: DATA STREAM</P> 929 */ 930 public static final String DATA = "_data"; 931 932 /** 933 * The time the file was added to the media provider 934 * Units are seconds since 1970. 935 * <P>Type: INTEGER (long)</P> 936 */ 937 public static final String DATE_ADDED = "date_added"; 938 939 /** 940 * The time the file was last modified 941 * Units are seconds since 1970. 942 * NOTE: This is for internal use by the media scanner. Do not modify this field. 943 * <P>Type: INTEGER (long)</P> 944 */ 945 public static final String DATE_MODIFIED = "date_modified"; 946 } 947 948 /** 949 * Contains playlists for audio files 950 */ 951 public static final class Playlists implements BaseColumns, 952 PlaylistsColumns { 953 /** 954 * Get the content:// style URI for the audio playlists table on the 955 * given volume. 956 * 957 * @param volumeName the name of the volume to get the URI for 958 * @return the URI to the audio playlists table on the given volume 959 */ 960 public static Uri getContentUri(String volumeName) { 961 return Uri.parse(CONTENT_AUTHORITY_SLASH + volumeName + 962 "/audio/playlists"); 963 } 964 965 /** 966 * The content:// style URI for the internal storage. 967 */ 968 public static final Uri INTERNAL_CONTENT_URI = 969 getContentUri("internal"); 970 971 /** 972 * The content:// style URI for the "primary" external storage 973 * volume. 974 */ 975 public static final Uri EXTERNAL_CONTENT_URI = 976 getContentUri("external"); 977 978 /** 979 * The MIME type for this table. 980 */ 981 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/playlist"; 982 983 /** 984 * The MIME type for entries in this table. 985 */ 986 public static final String ENTRY_CONTENT_TYPE = "vnd.android.cursor.item/playlist"; 987 988 /** 989 * The default sort order for this table 990 */ 991 public static final String DEFAULT_SORT_ORDER = NAME; 992 993 /** 994 * Sub-directory of each playlist containing all members. 995 */ 996 public static final class Members implements AudioColumns { 997 public static final Uri getContentUri(String volumeName, 998 long playlistId) { 999 return Uri.parse(CONTENT_AUTHORITY_SLASH + volumeName 1000 + "/audio/playlists/" + playlistId + "/members"); 1001 } 1002 1003 /** 1004 * The ID within the playlist. 1005 */ 1006 public static final String _ID = "_id"; 1007 1008 /** 1009 * A subdirectory of each playlist containing all member audio 1010 * files. 1011 */ 1012 public static final String CONTENT_DIRECTORY = "members"; 1013 1014 /** 1015 * The ID of the audio file 1016 * <P>Type: INTEGER (long)</P> 1017 */ 1018 public static final String AUDIO_ID = "audio_id"; 1019 1020 /** 1021 * The ID of the playlist 1022 * <P>Type: INTEGER (long)</P> 1023 */ 1024 public static final String PLAYLIST_ID = "playlist_id"; 1025 1026 /** 1027 * The order of the songs in the playlist 1028 * <P>Type: INTEGER (long)></P> 1029 */ 1030 public static final String PLAY_ORDER = "play_order"; 1031 1032 /** 1033 * The default sort order for this table 1034 */ 1035 public static final String DEFAULT_SORT_ORDER = PLAY_ORDER; 1036 } 1037 } 1038 1039 /** 1040 * Columns representing an artist 1041 */ 1042 public interface ArtistColumns { 1043 /** 1044 * The artist who created the audio file, if any 1045 * <P>Type: TEXT</P> 1046 */ 1047 public static final String ARTIST = "artist"; 1048 1049 /** 1050 * A non human readable key calculated from the ARTIST, used for 1051 * searching, sorting and grouping 1052 * <P>Type: TEXT</P> 1053 */ 1054 public static final String ARTIST_KEY = "artist_key"; 1055 1056 /** 1057 * The number of albums in the database for this artist 1058 */ 1059 public static final String NUMBER_OF_ALBUMS = "number_of_albums"; 1060 1061 /** 1062 * The number of albums in the database for this artist 1063 */ 1064 public static final String NUMBER_OF_TRACKS = "number_of_tracks"; 1065 } 1066 1067 /** 1068 * Contains artists for audio files 1069 */ 1070 public static final class Artists implements BaseColumns, ArtistColumns { 1071 /** 1072 * Get the content:// style URI for the artists table on the 1073 * given volume. 1074 * 1075 * @param volumeName the name of the volume to get the URI for 1076 * @return the URI to the audio artists table on the given volume 1077 */ 1078 public static Uri getContentUri(String volumeName) { 1079 return Uri.parse(CONTENT_AUTHORITY_SLASH + volumeName + 1080 "/audio/artists"); 1081 } 1082 1083 /** 1084 * The content:// style URI for the internal storage. 1085 */ 1086 public static final Uri INTERNAL_CONTENT_URI = 1087 getContentUri("internal"); 1088 1089 /** 1090 * The content:// style URI for the "primary" external storage 1091 * volume. 1092 */ 1093 public static final Uri EXTERNAL_CONTENT_URI = 1094 getContentUri("external"); 1095 1096 /** 1097 * The MIME type for this table. 1098 */ 1099 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/artists"; 1100 1101 /** 1102 * The MIME type for entries in this table. 1103 */ 1104 public static final String ENTRY_CONTENT_TYPE = "vnd.android.cursor.item/artist"; 1105 1106 /** 1107 * The default sort order for this table 1108 */ 1109 public static final String DEFAULT_SORT_ORDER = ARTIST_KEY; 1110 1111 /** 1112 * Sub-directory of each artist containing all albums on which 1113 * a song by the artist appears. 1114 */ 1115 public static final class Albums implements AlbumColumns { 1116 public static final Uri getContentUri(String volumeName, 1117 long artistId) { 1118 return Uri.parse(CONTENT_AUTHORITY_SLASH + volumeName 1119 + "/audio/artists/" + artistId + "/albums"); 1120 } 1121 } 1122 } 1123 1124 /** 1125 * Columns representing an album 1126 */ 1127 public interface AlbumColumns { 1128 1129 /** 1130 * The id for the album 1131 * <P>Type: INTEGER</P> 1132 */ 1133 public static final String ALBUM_ID = "album_id"; 1134 1135 /** 1136 * The album on which the audio file appears, if any 1137 * <P>Type: TEXT</P> 1138 */ 1139 public static final String ALBUM = "album"; 1140 1141 /** 1142 * The artist whose songs appear on this album 1143 * <P>Type: TEXT</P> 1144 */ 1145 public static final String ARTIST = "artist"; 1146 1147 /** 1148 * The number of songs on this album 1149 * <P>Type: INTEGER</P> 1150 */ 1151 public static final String NUMBER_OF_SONGS = "numsongs"; 1152 1153 /** 1154 * This column is available when getting album info via artist, 1155 * and indicates the number of songs on the album by the given 1156 * artist. 1157 * <P>Type: INTEGER</P> 1158 */ 1159 public static final String NUMBER_OF_SONGS_FOR_ARTIST = "numsongs_by_artist"; 1160 1161 /** 1162 * The year in which the earliest songs 1163 * on this album were released. This will often 1164 * be the same as {@link #LAST_YEAR}, but for compilation albums 1165 * they might differ. 1166 * <P>Type: INTEGER</P> 1167 */ 1168 public static final String FIRST_YEAR = "minyear"; 1169 1170 /** 1171 * The year in which the latest songs 1172 * on this album were released. This will often 1173 * be the same as {@link #FIRST_YEAR}, but for compilation albums 1174 * they might differ. 1175 * <P>Type: INTEGER</P> 1176 */ 1177 public static final String LAST_YEAR = "maxyear"; 1178 1179 /** 1180 * A non human readable key calculated from the ALBUM, used for 1181 * searching, sorting and grouping 1182 * <P>Type: TEXT</P> 1183 */ 1184 public static final String ALBUM_KEY = "album_key"; 1185 1186 /** 1187 * Cached album art. 1188 * <P>Type: TEXT</P> 1189 */ 1190 public static final String ALBUM_ART = "album_art"; 1191 } 1192 1193 /** 1194 * Contains artists for audio files 1195 */ 1196 public static final class Albums implements BaseColumns, AlbumColumns { 1197 /** 1198 * Get the content:// style URI for the albums table on the 1199 * given volume. 1200 * 1201 * @param volumeName the name of the volume to get the URI for 1202 * @return the URI to the audio albums table on the given volume 1203 */ 1204 public static Uri getContentUri(String volumeName) { 1205 return Uri.parse(CONTENT_AUTHORITY_SLASH + volumeName + 1206 "/audio/albums"); 1207 } 1208 1209 /** 1210 * The content:// style URI for the internal storage. 1211 */ 1212 public static final Uri INTERNAL_CONTENT_URI = 1213 getContentUri("internal"); 1214 1215 /** 1216 * The content:// style URI for the "primary" external storage 1217 * volume. 1218 */ 1219 public static final Uri EXTERNAL_CONTENT_URI = 1220 getContentUri("external"); 1221 1222 /** 1223 * The MIME type for this table. 1224 */ 1225 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/albums"; 1226 1227 /** 1228 * The MIME type for entries in this table. 1229 */ 1230 public static final String ENTRY_CONTENT_TYPE = "vnd.android.cursor.item/album"; 1231 1232 /** 1233 * The default sort order for this table 1234 */ 1235 public static final String DEFAULT_SORT_ORDER = ALBUM_KEY; 1236 } 1237 } 1238 1239 public static final class Video { 1240 1241 /** 1242 * The default sort order for this table. 1243 */ 1244 public static final String DEFAULT_SORT_ORDER = MediaColumns.DISPLAY_NAME; 1245 1246 public static final Cursor query(ContentResolver cr, Uri uri, String[] projection) 1247 { 1248 return cr.query(uri, projection, null, null, DEFAULT_SORT_ORDER); 1249 } 1250 1251 public interface VideoColumns extends MediaColumns { 1252 1253 /** 1254 * The duration of the video file, in ms 1255 * <P>Type: INTEGER (long)</P> 1256 */ 1257 public static final String DURATION = "duration"; 1258 1259 /** 1260 * The artist who created the video file, if any 1261 * <P>Type: TEXT</P> 1262 */ 1263 public static final String ARTIST = "artist"; 1264 1265 /** 1266 * The album the video file is from, if any 1267 * <P>Type: TEXT</P> 1268 */ 1269 public static final String ALBUM = "album"; 1270 1271 /** 1272 * The resolution of the video file, formatted as "XxY" 1273 * <P>Type: TEXT</P> 1274 */ 1275 public static final String RESOLUTION = "resolution"; 1276 1277 /** 1278 * The description of the video recording 1279 * <P>Type: TEXT</P> 1280 */ 1281 public static final String DESCRIPTION = "description"; 1282 1283 /** 1284 * Whether the video should be published as public or private 1285 * <P>Type: INTEGER</P> 1286 */ 1287 public static final String IS_PRIVATE = "isprivate"; 1288 1289 /** 1290 * The user-added tags associated with a video 1291 * <P>Type: TEXT</P> 1292 */ 1293 public static final String TAGS = "tags"; 1294 1295 /** 1296 * The YouTube category of the video 1297 * <P>Type: TEXT</P> 1298 */ 1299 public static final String CATEGORY = "category"; 1300 1301 /** 1302 * The language of the video 1303 * <P>Type: TEXT</P> 1304 */ 1305 public static final String LANGUAGE = "language"; 1306 1307 /** 1308 * The latitude where the image was captured. 1309 * <P>Type: DOUBLE</P> 1310 */ 1311 public static final String LATITUDE = "latitude"; 1312 1313 /** 1314 * The longitude where the image was captured. 1315 * <P>Type: DOUBLE</P> 1316 */ 1317 public static final String LONGITUDE = "longitude"; 1318 1319 /** 1320 * The date & time that the image was taken in units 1321 * of milliseconds since jan 1, 1970. 1322 * <P>Type: INTEGER</P> 1323 */ 1324 public static final String DATE_TAKEN = "datetaken"; 1325 1326 /** 1327 * The mini thumb id. 1328 * <P>Type: INTEGER</P> 1329 */ 1330 public static final String MINI_THUMB_MAGIC = "mini_thumb_magic"; 1331 1332 /** 1333 * The bucket id of the video. This is a read-only property that 1334 * is automatically computed from the DATA column. 1335 * <P>Type: TEXT</P> 1336 */ 1337 public static final String BUCKET_ID = "bucket_id"; 1338 1339 /** 1340 * The bucket display name of the video. This is a read-only property that 1341 * is automatically computed from the DATA column. 1342 * <P>Type: TEXT</P> 1343 */ 1344 public static final String BUCKET_DISPLAY_NAME = "bucket_display_name"; 1345 1346 /** 1347 * The bookmark for the video. Time in ms. Represents the location in the video that the 1348 * video should start playing at the next time it is opened. If the value is null or 1349 * out of the range 0..DURATION-1 then the video should start playing from the 1350 * beginning. 1351 * <P>Type: INTEGER</P> 1352 */ 1353 public static final String BOOKMARK = "bookmark"; 1354 } 1355 1356 public static final class Media implements VideoColumns { 1357 /** 1358 * Get the content:// style URI for the video media table on the 1359 * given volume. 1360 * 1361 * @param volumeName the name of the volume to get the URI for 1362 * @return the URI to the video media table on the given volume 1363 */ 1364 public static Uri getContentUri(String volumeName) { 1365 return Uri.parse(CONTENT_AUTHORITY_SLASH + volumeName + 1366 "/video/media"); 1367 } 1368 1369 /** 1370 * The content:// style URI for the internal storage. 1371 */ 1372 public static final Uri INTERNAL_CONTENT_URI = 1373 getContentUri("internal"); 1374 1375 /** 1376 * The content:// style URI for the "primary" external storage 1377 * volume. 1378 */ 1379 public static final Uri EXTERNAL_CONTENT_URI = 1380 getContentUri("external"); 1381 1382 /** 1383 * The MIME type for this table. 1384 */ 1385 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/video"; 1386 1387 /** 1388 * The default sort order for this table 1389 */ 1390 public static final String DEFAULT_SORT_ORDER = TITLE; 1391 } 1392 } 1393 1394 /** 1395 * Uri for querying the state of the media scanner. 1396 */ 1397 public static Uri getMediaScannerUri() { 1398 return Uri.parse(CONTENT_AUTHORITY_SLASH + "none/media_scanner"); 1399 } 1400 1401 /** 1402 * Name of current volume being scanned by the media scanner. 1403 */ 1404 public static final String MEDIA_SCANNER_VOLUME = "volume"; 1405} 1406