-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdroptarget.java
More file actions
32 lines (28 loc) · 1.18 KB
/
Copy pathdroptarget.java
File metadata and controls
32 lines (28 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
protected class DropTargetListener implements View.OnDragListener {
@Override
public boolean onDrag(View v, DragEvent event) {
final int action = event.getAction();
switch(action) {
...
case DragEvent.ACTION_DROP:
requestDragAndDropPermissions(event); //Allow items from other applications
ClipData.Item item = event.getClipData().getItemAt(0);
//Note: application/x-arc-uri-list is MIME-type for Chrome OS files dropped into the app
if (event.getClipDescription().hasMimeType("application/x-arc-uri-list")) {
Uri contentUri = item.getUri();
ParcelFileDescriptor parcelFileDescriptor;
try {
parcelFileDescriptor = getContentResolver().openFileDescriptor(contentUri, "r");
} catch (FileNotFoundException e) {
e.printStackTrace();
return false;
}
FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor();
} else {
return false;
}
return true;
...
}
}
}