我正在开发视频播放器,其中想要使用列表添加我的播放器以完成操作,我将在清单中添加代码:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:mimeType="video/*" />
<data android:mimeType="application/sdp" />
<data android:pathPattern=".*3gp" />
<data android:pathPattern=".*3GP" />
<data android:pathPattern=".*mp4" />
<data android:pathPattern=".*MP4" />
</intent-filter>
当我在播放机中从图库中打开视频时,它就能正常工作。
在我获取视频代码URI的活动中:
Intent i = getIntent();
Uri tmpSelectedImageUri = i.getData();
filename = getPath(tmpSelectedImageUri, ViewVideo.this);
public String getPath(Uri uri, Activity activity) {
String[] projection = { MediaColumns.DATA };
Cursor cursor = activity.managedQuery(uri, projection, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaColumns.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
问题是,当我从whatsApp打开视频到我的播放器时,它会在此行中显示NullPointerException Uri tmpSelectedImageUri = i.getData();
答案 0 :(得分:0)
试试这个:
String type = intent.getType();
if (type.equal("text/plain")){
Log.d("DATA", "Type text: " + intent.getStringExtra(Intent.EXTRA_TEXT));
//tmpSelectedImageUri = Uri.parse(intent.getStringExtra(Intent.EXTRA_TEXT));
} else if (type.startsWith("video/")) {
tmpSelectedImageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
}