I want to show user selection to choose my application as default video player. For that purpose i am using following code in AndroidManifest.xml
<activity
android:name=".video.NewVideoPlayerActivity"
android:enabled="true"
android:exported="true"
android:icon="@drawable/ic_launcher">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="video/mp4" />
</intent-filter>
</activity>
By using above code i am able to show my application in selection of default video player as option. But i am unable to get Absolute Path of video file selected by user. I have used following code to get Video path in activity.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getIntent() != null) {
if (getIntent().getAction() != null) {
if (getIntent().getAction().equals(Intent.ACTION_VIEW)) {
if (getIntent().getData() != null) {
//stringExtra = getIntent().getData().getPath();
Logger.getInstance().error(getRealPathFromURI(getIntent().getData()));
}
}
}
}
}
public String getRealPathFromURI( Uri contentUri) {
Cursor cursor = null;
try {
String[] proj = { MediaStore.Video.Media.DATA };
cursor = getContentResolver().query(contentUri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
} finally {
if (cursor != null) {
cursor.close();
}
}
}
This is what i have tried. How i can show user my player as default video player chooser and get user selected video path in my activity?