|
1 | 1 | package com.filebrowser.amit_gupta.filebrowser; |
2 | 2 |
|
| 3 | +import android.content.Intent; |
| 4 | +import android.content.pm.PackageManager; |
| 5 | +import android.content.pm.ResolveInfo; |
| 6 | +import android.net.Uri; |
3 | 7 | import android.os.Bundle; |
4 | 8 | import android.os.Environment; |
5 | 9 | import android.support.design.widget.FloatingActionButton; |
@@ -33,6 +37,8 @@ public class FileBrowser extends AppCompatActivity |
33 | 37 | private int totalSize; |
34 | 38 | ListView listView; |
35 | 39 | TextView textView; |
| 40 | + private final int PICK_FILE_RESULT_CODE = 999; |
| 41 | + private long timeStamp; |
36 | 42 |
|
37 | 43 | @Override |
38 | 44 | protected void onCreate(Bundle savedInstanceState) { |
@@ -99,7 +105,11 @@ public void onBackPressed() { |
99 | 105 | listView.setAdapter(new ArrayAdapter(this, |
100 | 106 | android.R.layout.simple_list_item_1, myList)); |
101 | 107 | }else { |
102 | | - Toast.makeText(getApplicationContext(),"AT THE ROOT - no more back", Toast.LENGTH_SHORT).show(); |
| 108 | + Toast.makeText(getApplicationContext(),"AT THE ROOT Folder, press one more back to Exit App", Toast.LENGTH_SHORT).show(); |
| 109 | + if(System.currentTimeMillis() - timeStamp < 200){ |
| 110 | + super.onBackPressed(); |
| 111 | + } |
| 112 | + timeStamp = System.currentTimeMillis(); |
103 | 113 | } |
104 | 114 | // super.onBackPressed(); |
105 | 115 | } |
@@ -176,6 +186,50 @@ public void onItemClick(AdapterView<?> adapterView, View view, int j, long l) { |
176 | 186 | Toast.makeText(getApplicationContext(),"Folder is Empty", Toast.LENGTH_SHORT).show(); |
177 | 187 | } |
178 | 188 |
|
| 189 | + }else { |
| 190 | + String mimeType = MediaFile.getMimeTypeForFile(temp_file.toString()); //getContentResolver().getType(Uri.parse("file://" + temp_file)); |
| 191 | + String fileName = temp_file.getName(); |
| 192 | + int dotposition= fileName.lastIndexOf("."); |
| 193 | + String file_Extension = ""; |
| 194 | + if(dotposition != -1) { |
| 195 | + String filename_Without_Ext = fileName.substring(0, dotposition); |
| 196 | + file_Extension = fileName.substring(dotposition + 1, fileName.length()); |
| 197 | + } |
| 198 | + |
| 199 | + Intent intent = new Intent(); |
| 200 | + intent.setAction(Intent.ACTION_VIEW); |
| 201 | + intent.setDataAndType(Uri.parse("file://" + temp_file), mimeType); |
| 202 | + ResolveInfo info = getPackageManager().resolveActivity(intent, |
| 203 | + PackageManager.MATCH_DEFAULT_ONLY); |
| 204 | + if (info != null) { |
| 205 | + startActivity(Intent.createChooser(intent, "Complete action using")); |
| 206 | + // startActivity(intent); |
| 207 | + } |
179 | 208 | } |
180 | 209 | } |
| 210 | +// void pickFile(File aFile) { |
| 211 | +// Intent theIntent = new Intent(Intent.ACTION_PICK); |
| 212 | +// theIntent.setData(Uri.fromFile(aFile)); //default file / jump directly to this file/folder |
| 213 | +// theIntent.putExtra(Intent.EXTRA_TITLE,"A Custom Title"); //optional |
| 214 | +// theIntent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); //optional |
| 215 | +// try { |
| 216 | +// startActivityForResult(theIntent,PICK_FILE_RESULT_CODE); |
| 217 | +// } catch (Exception e) { |
| 218 | +// e.printStackTrace(); |
| 219 | +// } |
| 220 | +// } |
| 221 | + |
| 222 | + @Override |
| 223 | + protected void onActivityResult(int requestCode, int resultCode, Intent data){ |
| 224 | + switch (requestCode) { |
| 225 | + case PICK_FILE_RESULT_CODE: { |
| 226 | + if (resultCode==RESULT_OK && data!=null && data.getData() !=null) { |
| 227 | + String theFilePath = data.getData().getPath(); |
| 228 | + //handle code |
| 229 | + } |
| 230 | + break; |
| 231 | + } |
| 232 | + } |
| 233 | + } |
| 234 | + |
181 | 235 | } |
0 commit comments