This document summarizes key points about ContentProviders in Android:
- ContentProviders allow applications to access data via a uniform resource identifier (URI). The URI is defined in the AndroidManifest.xml file.
- Common Android data sources that can be accessed via ContentProviders include contacts, call logs, media files, and device settings.
- The query() method is used to query a ContentProvider and return cursor results. Selection clauses and sorting can be specified.
2. CONFIDENTIAL INFORMATION
This document is confidential and proprietary information of
Target Soft Systems. Confidential Information includes, but is not
limited to, the following:
Corporate, Employee and Infrastructure Information about Target
Soft Systems.
Target Soft Systems implementation , Training methodology, cost,
project management and quality processes.
Any disclosure of Confidential Information to, or use of it by a
third party (i.e., a party other than authorised , will be damaging to
Target Soft Systems). Ownership of all Confidential Information,
no matter in what media it resides, remains with Target Soft
Systems( TSS ).
Confidential Information in this document shall not be disclosed
outside the buyer’s proposal evaluators and shall not be duplicated,
used, or disclosed – in whole or in part – for any purpose other than
to evaluate this proposal without specific written permission of an
authorized representative of Target Soft Systems.
3. • * If you want to share data with other applications you can use a
ContentProvider.
• * A ContentProvider allows applications to access data.
• * The access to a ContentProvider is done via an URI (Uniform
Resource Identifier). The basis for the URI is defined in the
declaration of the ContentProvider in the AndroidManifest.xml
file via the android:authorities attribute.
• * Many Android data sources, e.g. the contacts, are accessible
via ContentProviders. Typically the implementing classes for a
ContentProviders provide public constants for the URIs.
4. Some of the useful Content Providers are,
Browser – Stores data such as browser bookmarks, history
CallLog – Stores data such as missed calls, call details.
Contacts – Stores Contact Details
MediaStore – Stores media files such as audio, video and
images
Settings – Stores the settings of the device and preferences.
Format of the query string URI (Uniform Resource Identifier)
<Standard Prefix >://<authority>/<data_path>/<id>
5.
6. public final Cursor managedQuery (Uri uri, String[] projection,
String selection, String[] selectionArgs, String sortOrder)
Parameters:
uri --The URI of the content provider to query.
projection --List of columns to return.
selection --SQL WHERE clause.
selectionArgs --The arguments to selection, if any ?s are present
sortOrder --SQL ORDER BY clause.
Returns:
The Cursor returned by query ().
7. import android.provider.CallLog;
import android.database.Cursor;
// Form an array specifying the columns to return.
String[] callLogColumnList = new String[] {
CallLog.Calls.NUMBER,
CallLog.Calls.CACHED_NAME,
CallLog.Calls.DATE, CallLog.Calls.DURATION,
CallLog.Calls.TYPE };
// Get the base URI for the People table in the Contacts content
provider.
Uri callLogs = CallLog.Calls.CONTENT_URI;
Uri callLogs = Uri.parse(“content://call_logs/calls”);
8. // Make the query.
Cursor managedCursor = managedQuery (callLogs,
callLogColumnList, // which columns to return
null, // Which rows to return (all rows) null,
// Selection arguments (none)
CallLog.Calls.DATE + "DESC" //results in descending
order by date);
10. Media Player
MediaPlayer class can be used to control playback of
audio/video files and streams. Playback control of audio/video
files and streams is managed as a state machine.
• publicstatic MediaPlayer create (Context context, Uri
uri, SurfaceHolderholder)
• Added in API level 1
• Convenience method to create a MediaPlayer for a given Uri.
On success, prepare() will already have been called and must
not be called again.
11. When done with the MediaPlayer, you should
call release(), to free the resources. If not released, too many
MediaPlayer instances will result in an exception.
Parameters
Context the Context to use uri the Uri from which to get
the data source holder the SurfaceHolder to use for displaying the
video
Returns
a MediaPlayer object, or null if creation failed
12. ACTIVITY LIFE CYCLEACTIVITY LIFE CYCLE
onCreate( )
onStart( )
onPause( )
onResume( )
onStop( )
onRestart( )
onDestroy( )
15. Supported Media Formats
Audio Format :
3GPP (.3gp)
MPEG-4 (.mp4, .m4a)
ADTS raw AAC (.aac, decode in Android 3.1+, encode in
Android 4.0+, ADIF not supported)
MP3 (.mp3)
WAVE (.wav)
16. MediaPlayer mp = new MediaPlayer();
// Set data source -
setDataSource("/sdcard/path_to_song");
// Play audio
mp.start();
// Pause audio
mp.pause();
// Reset mediaplayer
mp.reset();
// Get song length duration - in milliseconds
mp.getDuration();
// Get current duration - in milliseconds
mp.getCurrentDuration();
// Move song to particular second - used for Forward or Backward
mp.seekTo(positon); // position in milliseconds
// Check if song is playing or not
mp.isPlaying(); // returns true or false
Audio Player
17. Video Format :
3GPP (.3gp)
MPEG-4 (.mp4)
WebM (.webm)
Matroska (.mkv, Android 4.0+)
Image Format :
JPEG (.jpg)
GIF (.gif)
PNG (.png)
BMP (.bmp)
Supported Media Formats
18. VideoView videoView =(VideoView)findViewById(R.id.videoView);
MediaController mediaController= new MediaController(this);
mediaController.setAnchorView(videoView);
Uri uri=Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.one);
videoView.setMediaController(mediaController);
videoView.setVideoURI(uri);
videoView.requestFocus();
videoView.start();
videoView.stopPlayback();
videoView.pause();
videoView.isPlaying();
videoView.getDuration();
videoView.getCurrentPosition();
Video Player