找到你要的答案

Q:Complete Action using in My video player

Q:在我的视频播放器中使用完整的动作

I am developing Video Player in which want to add my player in complete action using list for that i will add code in manifest:

<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> 

When I open video from gallery in my player then it work.

In My activity for getting URI of video code:

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); 
}

Problem is when I open Video from whatsApp to my player it show NullPointerException in this line Uri tmpSelectedImageUri = i.getData();

我正在开发的视频播放器,其中要添加我的球员在完整的行动使用列表,我将添加代码在清单:

<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我的球员在这tmpselectedimageuri =我getdata() NullPointerException URI;

answer1: 回答1:

Try this:

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);
}

试试这个:

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);
}
android  video  whatsapp