在网上看到很多类似的Demo,我刚入行很多都看不懂,最后自己弄出来这个,可以自动播放视频,但是只能播放名字为"video.mp4"的视频,也是得先打开Apk再插入U盘才能跳转播放,有大佬可以指点一下怎么修改吗?
public class UsbVideo extends Activity {protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.usb_video);IntentFilter intentFilter = new IntentFilter();UsbBroadcastReceive usbBroadcastReceive = new UsbBroadcastReceive();intentFilter.addAction("android.intent.action.MEDIA_EJECT");intentFilter.addAction("android.intent.action.MEDIA_MOUNTED");intentFilter.addAction("android.intent.action.MEDIA_REMOVED");intentFilter.addAction("android.intent.action.MEDIA_UNMOUNTED");intentFilter.addDataScheme("file");registerReceiver(usbBroadcastReceive, intentFilter);}class UsbBroadcastReceive extends BroadcastReceiver {@Overridepublic void onReceive(Context context, Intent intent) {String action = intent.getAction();if ("android.intent.action.MEDIA_MOUNTED".equalsIgnoreCase(action)) {String usbPath = intent.getDataString();if (TextUtils.isEmpty(usbPath)) {return;}usbPath = usbPath.replace("file:///", "");Uri videoUri = Uri.parse(usbPath + "/video.mp4");// 启动视频播放Intent startVideoIntent = new Intent(Intent.ACTION_VIEW, videoUri);startVideoIntent.setDataAndType(videoUri, "video/mp4");startVideoIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);startActivity(startVideoIntent);return;} else if (action.equals(Intent.ACTION_MEDIA_UNMOUNTED) || action.equals(Intent.ACTION_MEDIA_EJECT)) {Log.e("TAG", "U盘移除");return;} else if (action.equals("android.intent.action.BOOT_COMPLETED")) {return;}}}
}
<!--SD卡读写的权限--><uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/><uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>