可以说我有一个网址(它不具体,它将是一个 youtube 链接)
单击缩略图/按钮时,我想触发 android 中的弹出排序,询问要使用哪个播放器。
我知道有很多关于它的文章,但我无法让它发挥作用。
我试过这个:
package com.example.videotry;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.view.View.OnClickListener;
public class Play extends Activity implements OnClickListener {
@Override
public void onClick(View v) {
if (v.getId() == R.id.imageButton1) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setType("video/*");
intent.setData(Uri.parse("http://www.youtube.com/embed/PW_88sL_2dA?feature=oembed" ));
startActivity(Intent.createChooser(intent, "Complete action using"));
}
}
}
但它会引发错误:
07-22 15:08:00.680: E/AndroidRuntime(8163): java.lang.NullPointerException
07-22 15:08:00.680: E/AndroidRuntime(8163): at android.app.Activity.startActivityForResult(Activity.java:3190)
07-22 15:08:00.680: E/AndroidRuntime(8163): at android.app.Activity.startActivity(Activity.java:3297)
07-22 15:08:00.680: E/AndroidRuntime(8163): at com.example.videotry.Play.onClick(Play.java:18)
07-22 15:08:00.680: E/AndroidRuntime(8163): at android.view.View.performClick(View.java:3511)
07-22 15:08:00.680: E/AndroidRuntime(8163): at android.view.View$PerformClick.run(View.java:14110)
07-22 15:08:00.680: E/AndroidRuntime(8163): at android.os.Handler.handleCallback(Handler.java:605)
07-22 15:08:00.680: E/AndroidRuntime(8163): at android.os.Handler.dispatchMessage(Handler.java:92)
07-22 15:08:00.680: E/AndroidRuntime(8163): at android.os.Looper.loop(Looper.java:137)
07-22 15:08:00.680: E/AndroidRuntime(8163): at android.app.ActivityThread.main(ActivityThread.java:4424)
07-22 15:08:00.680: E/AndroidRuntime(8163): at java.lang.reflect.Method.invokeNative(Native Method)
07-22 15:08:00.680: E/AndroidRuntime(8163): at java.lang.reflect.Method.invoke(Method.java:511)
07-22 15:08:00.680: E/AndroidRuntime(8163): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-22 15:08:00.680: E/AndroidRuntime(8163): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-22 15:08:00.680: E/AndroidRuntime(8163): at dalvik.system.NativeStart.main(Native Method)
这与视频格式无关。我尝试了不同的格式。我正在使用安卓 4.0
我也试过 ACTION_VIEW