0

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?

James Z
  • 12,209
  • 10
  • 24
  • 44
  • 1
    Does https://stackoverflow.com/questions/19985286/convert-content-uri-to-actual-path-in-android-4-4 answer your question ? There is code to translate content:/..../ uri with id to path and there is the info that the android way to use content is to use Contentresolver + inputstream instead of file. – k3b Mar 19 '18 at 16:30
  • This solution worked thanks. – Lovish Sindhwani Mar 21 '18 at 05:52

0 Answers0