@TargetApi(Build.VERSION_CODES.HONEYCOMB) public static boolean deleteFile(String path) { boolean deleted = false; path = Uri.decode(Strings.removeFileProtocole(path)); // Delete from Android Medialib, for consistency with device MTP storing and other apps listing // content:// media if (AndroidUtil.isHoneycombOrLater()) { ContentResolver cr = VLCApplication.getAppContext().getContentResolver(); String[] selectionArgs = {path}; deleted = cr.delete( MediaStore.Files.getContentUri("external"), MediaStore.Files.FileColumns.DATA + "=?", selectionArgs) > 0; } File file = new File(path); if (file.exists()) deleted |= file.delete(); return deleted; }
@TargetApi(Build.VERSION_CODES.HONEYCOMB) public void onContextPopupMenu(View anchor, final int position) { if (!AndroidUtil.isHoneycombOrLater()) { // Call the "classic" context menu anchor.performLongClick(); return; } PopupMenu popupMenu = new PopupMenu(getActivity(), anchor); popupMenu.getMenuInflater().inflate(R.menu.video_list, popupMenu.getMenu()); MediaWrapper media = mVideoAdapter.getItem(position); if (media == null) return; setContextMenuItems(popupMenu.getMenu(), media); popupMenu.setOnMenuItemClickListener( new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { return handleContextItemSelected(item, position); } }); popupMenu.show(); }