Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.
/ os-fileup Public archive

Commit 9d96d7b

Browse files
committed
Main Activity (updated instructions)
1 parent 7b0a047 commit 9d96d7b

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

app/src/main/java/com/inf/os/fileup/MainActivity.java

+14-10
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,21 @@ public class MainActivity extends AppCompatActivity{
4545
private ValueCallback<Uri[]> mUMA;
4646
private final static int FCR=1;
4747

48-
//select whether you want to upload multiple files
48+
//select whether you want to upload multiple files (set 'true' for yes)
4949
private boolean multiple_files = false;
5050

5151
@Override
5252
protected void onActivityResult(int requestCode, int resultCode, Intent intent){
5353
super.onActivityResult(requestCode, resultCode, intent);
5454
if(Build.VERSION.SDK_INT >= 21){
5555
Uri[] results = null;
56-
//Check if response is positive
56+
//checking if response is positive
5757
if(resultCode== Activity.RESULT_OK){
5858
if(requestCode == FCR){
5959
if(null == mUMA){
6060
return;
6161
}
6262
if(intent == null || intent.getData() == null){
63-
//Capture Photo if no image available
6463
if(mCM != null){
6564
results = new Uri[]{Uri.parse(mCM)};
6665
}
@@ -119,9 +118,9 @@ protected void onCreate(Bundle savedInstanceState){
119118
webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
120119
}
121120
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
123122
webView.setWebChromeClient(new WebChromeClient() {
124-
//Handling input[type="file"] requests for android API 16+
123+
//handling input[type="file"] requests for android API 16+
125124
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
126125
mUM = uploadMsg;
127126
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
@@ -133,19 +132,19 @@ public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, Str
133132
startActivityForResult(Intent.createChooser(i, "File Chooser"), FCR);
134133
}
135134

136-
//Handling input[type="file"] requests for android API 21+
135+
//handling input[type="file"] requests for android API 21+
137136
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) {
138137
String[] perms = {Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.CAMERA};
139138

140-
//Checking for storage permission to write images for upload
139+
//checking for storage permission to write images for upload
141140
if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
142141
ActivityCompat.requestPermissions(MainActivity.this, perms, FCR);
143142

144-
//Checking for WRITE_EXTERNAL_STORAGE permission
143+
//checking for WRITE_EXTERNAL_STORAGE permission
145144
} else if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
146145
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE}, FCR);
147146

148-
//Checking for CAMERA permissions
147+
//checking for CAMERA permissions
149148
} else if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
150149
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.CAMERA}, FCR);
151150
}
@@ -192,18 +191,23 @@ public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathC
192191
}
193192
});
194193
}
194+
195+
//callback reporting if error occurs
195196
public class Callback extends WebViewClient{
196197
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl){
197198
Toast.makeText(getApplicationContext(), "Failed loading app!", Toast.LENGTH_SHORT).show();
198199
}
199200
}
200-
// Create an image file
201+
202+
//creating new image file here
201203
private File createImageFile() throws IOException{
202204
@SuppressLint("SimpleDateFormat") String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
203205
String imageFileName = "img_"+timeStamp+"_";
204206
File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
205207
return File.createTempFile(imageFileName,".jpg",storageDir);
206208
}
209+
210+
//back/down key handling
207211
@Override
208212
public boolean onKeyDown(int keyCode, @NonNull KeyEvent event){
209213
if(event.getAction() == KeyEvent.ACTION_DOWN){

0 commit comments

Comments
 (0)