@@ -45,22 +45,21 @@ public class MainActivity extends AppCompatActivity{
45
45
private ValueCallback <Uri []> mUMA ;
46
46
private final static int FCR =1 ;
47
47
48
- //select whether you want to upload multiple files
48
+ //select whether you want to upload multiple files (set 'true' for yes)
49
49
private boolean multiple_files = false ;
50
50
51
51
@ Override
52
52
protected void onActivityResult (int requestCode , int resultCode , Intent intent ){
53
53
super .onActivityResult (requestCode , resultCode , intent );
54
54
if (Build .VERSION .SDK_INT >= 21 ){
55
55
Uri [] results = null ;
56
- //Check if response is positive
56
+ //checking if response is positive
57
57
if (resultCode == Activity .RESULT_OK ){
58
58
if (requestCode == FCR ){
59
59
if (null == mUMA ){
60
60
return ;
61
61
}
62
62
if (intent == null || intent .getData () == null ){
63
- //Capture Photo if no image available
64
63
if (mCM != null ){
65
64
results = new Uri []{Uri .parse (mCM )};
66
65
}
@@ -119,9 +118,9 @@ protected void onCreate(Bundle savedInstanceState){
119
118
webView .setLayerType (View .LAYER_TYPE_SOFTWARE , null );
120
119
}
121
120
webView .setWebViewClient (new Callback ());
122
- webView .loadUrl ("file:///android_res/raw/index.html" );
121
+ webView .loadUrl ("file:///android_res/raw/index.html" ); //add your test web/page address here
123
122
webView .setWebChromeClient (new WebChromeClient () {
124
- //Handling input[type="file"] requests for android API 16+
123
+ //handling input[type="file"] requests for android API 16+
125
124
public void openFileChooser (ValueCallback <Uri > uploadMsg , String acceptType , String capture ) {
126
125
mUM = uploadMsg ;
127
126
Intent i = new Intent (Intent .ACTION_GET_CONTENT );
@@ -133,19 +132,19 @@ public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, Str
133
132
startActivityForResult (Intent .createChooser (i , "File Chooser" ), FCR );
134
133
}
135
134
136
- //Handling input[type="file"] requests for android API 21+
135
+ //handling input[type="file"] requests for android API 21+
137
136
public boolean onShowFileChooser (WebView webView , ValueCallback <Uri []> filePathCallback , FileChooserParams fileChooserParams ) {
138
137
String [] perms = {Manifest .permission .WRITE_EXTERNAL_STORAGE , Manifest .permission .READ_EXTERNAL_STORAGE , Manifest .permission .CAMERA };
139
138
140
- //Checking for storage permission to write images for upload
139
+ //checking for storage permission to write images for upload
141
140
if (ContextCompat .checkSelfPermission (MainActivity .this , Manifest .permission .WRITE_EXTERNAL_STORAGE ) != PackageManager .PERMISSION_GRANTED && ContextCompat .checkSelfPermission (MainActivity .this , Manifest .permission .CAMERA ) != PackageManager .PERMISSION_GRANTED ) {
142
141
ActivityCompat .requestPermissions (MainActivity .this , perms , FCR );
143
142
144
- //Checking for WRITE_EXTERNAL_STORAGE permission
143
+ //checking for WRITE_EXTERNAL_STORAGE permission
145
144
} else if (ContextCompat .checkSelfPermission (MainActivity .this , Manifest .permission .WRITE_EXTERNAL_STORAGE ) != PackageManager .PERMISSION_GRANTED ) {
146
145
ActivityCompat .requestPermissions (MainActivity .this , new String []{Manifest .permission .WRITE_EXTERNAL_STORAGE , Manifest .permission .READ_EXTERNAL_STORAGE }, FCR );
147
146
148
- //Checking for CAMERA permissions
147
+ //checking for CAMERA permissions
149
148
} else if (ContextCompat .checkSelfPermission (MainActivity .this , Manifest .permission .CAMERA ) != PackageManager .PERMISSION_GRANTED ) {
150
149
ActivityCompat .requestPermissions (MainActivity .this , new String []{Manifest .permission .CAMERA }, FCR );
151
150
}
@@ -192,18 +191,23 @@ public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathC
192
191
}
193
192
});
194
193
}
194
+
195
+ //callback reporting if error occurs
195
196
public class Callback extends WebViewClient {
196
197
public void onReceivedError (WebView view , int errorCode , String description , String failingUrl ){
197
198
Toast .makeText (getApplicationContext (), "Failed loading app!" , Toast .LENGTH_SHORT ).show ();
198
199
}
199
200
}
200
- // Create an image file
201
+
202
+ //creating new image file here
201
203
private File createImageFile () throws IOException {
202
204
@ SuppressLint ("SimpleDateFormat" ) String timeStamp = new SimpleDateFormat ("yyyyMMdd_HHmmss" ).format (new Date ());
203
205
String imageFileName = "img_" +timeStamp +"_" ;
204
206
File storageDir = Environment .getExternalStoragePublicDirectory (Environment .DIRECTORY_PICTURES );
205
207
return File .createTempFile (imageFileName ,".jpg" ,storageDir );
206
208
}
209
+
210
+ //back/down key handling
207
211
@ Override
208
212
public boolean onKeyDown (int keyCode , @ NonNull KeyEvent event ){
209
213
if (event .getAction () == KeyEvent .ACTION_DOWN ){
0 commit comments