Reputation: 1507
I am writing a camera application for Android, I want my application to be listed when video/photo is requested to be taken in applications like whatsapp messenger.
For example, in whatsapp when you click attach picture you can select the stock camera, or if I install vignette, I can use vignette.
How do I know which intent to listen to?
Thanks!
Upvotes: 1
Views: 1869
Reputation: 11107
You need to use Intent Filter to do this.
<activity android:name=".Activity" android:label="@string/app_name" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
If you add the Intent Filter with Data , category and data as given above , it will ask for Application if you need to share some Photos say Share Image outside of Application from image Gallery.
If you Select you application it will Redirect the Control to your Activity.
Inside you Activity you handle your Intent by using :
try{
Uri imageUri = (Uri) getIntent().getExtras().get(Intent.EXTRA_STREAM);
Cursor cursor = getContentResolver().query(imageUri, new String[] { android.provider.MediaStore.Images.ImageColumns.DATA }, null, null, null);
cursor.moveToFirst();
}catch(Exception e){
Log.v("Exception eeee", ""+e);
}
Now cursor will contains your selected image.
This is for Image chooser, you can use same for Video ,needed to change the mimitype in Manifest file of Intent Filter.
Upvotes: 2