16
16
import android .content .Intent ;
17
17
import android .content .pm .PackageManager ;
18
18
import android .content .res .Configuration ;
19
+ import android .graphics .Bitmap ;
19
20
import android .net .Uri ;
20
21
import android .os .Build ;
21
22
import android .os .Bundle ;
36
37
import android .webkit .WebViewClient ;
37
38
import android .widget .Toast ;
38
39
40
+ import java .io .ByteArrayOutputStream ;
39
41
import java .io .File ;
40
42
import java .io .IOException ;
41
43
import java .text .SimpleDateFormat ;
42
44
import java .util .Date ;
43
- import java .util .Iterator ;
44
- import java .util .Set ;
45
45
46
46
public class MainActivity extends AppCompatActivity {
47
47
48
48
/*-- CUSTOMIZE --*/
49
49
/*-- you can customize these options for your convenience --*/
50
50
private static String webview_url = "file:///android_res/raw/index.html" ; // web address or local file location you want to open in webview
51
- private static String file_type = "image /*" ; // file types to be allowed for upload
51
+ private static String file_type = "* /*" ; // file types to be allowed for upload
52
52
private boolean multiple_files = true ; // allowing multiple file upload
53
53
54
54
/*-- MAIN VARIABLES --*/
@@ -70,29 +70,25 @@ protected void onActivityResult(int requestCode, int resultCode, Intent intent){
70
70
71
71
/*-- if file request cancelled; exited camera. we need to send null value to make future attempts workable --*/
72
72
if (resultCode == Activity .RESULT_CANCELED ) {
73
- if (requestCode == file_req_code ) {
74
73
file_path .onReceiveValue (null );
75
74
return ;
76
- }
77
75
}
78
76
79
77
/*-- continue if response is positive --*/
80
78
if (resultCode == Activity .RESULT_OK ){
81
- if (requestCode == file_req_code ){
82
79
if (null == file_path ){
83
80
return ;
84
81
}
85
-
86
82
ClipData clipData ;
87
83
String stringData ;
84
+
88
85
try {
89
86
clipData = intent .getClipData ();
90
87
stringData = intent .getDataString ();
91
88
}catch (Exception e ){
92
89
clipData = null ;
93
90
stringData = null ;
94
91
}
95
-
96
92
if (clipData == null && stringData == null && cam_file_data != null ) {
97
93
results = new Uri []{Uri .parse (cam_file_data )};
98
94
}else {
@@ -103,11 +99,24 @@ protected void onActivityResult(int requestCode, int resultCode, Intent intent){
103
99
results [i ] = clipData .getItemAt (i ).getUri ();
104
100
}
105
101
} else {
102
+ try {
103
+ Bitmap cam_photo = (Bitmap ) intent .getExtras ().get ("data" );
104
+ ByteArrayOutputStream bytes = new ByteArrayOutputStream ();
105
+ cam_photo .compress (Bitmap .CompressFormat .JPEG , 100 , bytes );
106
+ stringData = MediaStore .Images .Media .insertImage (this .getContentResolver (), cam_photo , null , null );
107
+ }catch (Exception ignored ){}
108
+ /* checking extra data
109
+ Bundle bundle = intent.getExtras();
110
+ if (bundle != null) {
111
+ for (String key : bundle.keySet()) {
112
+ Log.w("ExtraData", key + " : " + (bundle.get(key) != null ? bundle.get(key) : "NULL"));
113
+ }
114
+ }*/
106
115
results = new Uri []{Uri .parse (stringData )};
107
116
}
108
117
}
109
118
}
110
- }
119
+
111
120
file_path .onReceiveValue (results );
112
121
file_path = null ;
113
122
}else {
0 commit comments