Reputation: 143
I need to create a service application which always looking and retrieve imaging file from if any new image taken from build in camera application.
1)My service needs to watching and taking the image from if new image was taken from build in camera application
how can we obtain the image path or image data in my service.
Upvotes: 6
Views: 957
Reputation: 11
FYI it is recommended to listen to the official broadcast since ICS API level 14: http://developer.android.com/reference/android/hardware/Camera.html#ACTION_NEW_PICTURE. So filter for "android.hardware.action.NEW_PICTURE", and use "com.android.camera.NEW_PICTURE" in addition only if you need to support pre-ICS as well.
Upvotes: 1
Reputation: 1252
manifest code:
<receiver android:name=".pictureReceiver" >
<intent-filter android:priority="10000" >
<action android:name="com.android.camera.NEW_PICTURE"/>
<data android:mimeType="image/*"/>
</intent-filter>
</receiver>
onReceive Code:
@Override
public void onReceive(Context arg0, Intent arg1) {
String selectedImageUri = arg1.getData().getPath();
Log.d("TAG", "Received new photo:::"+selectedImageUri );
Log.d("TAG","file Path"+getRealPathFromURI(arg1.getData(),arg0));
}
public String getRealPathFromURI(Uri contentUri,Context context)
{
try
{
String[] proj = {MediaStore.Images.Media.DATA};
Cursor cursor = context.getContentResolver().query(contentUri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
catch (Exception e)
{
return contentUri.getPath();
}
}
Upvotes: 5