//membaca working dinamic directory
// File rootDataDir = Aplikasi.this.getFilesDir();
// Log.v("PATHME", rootDataDir.toString());///data/data/id.ac.istn.appkripto/files
//membaca absolute directory
File file = Environment.getExternalStorageDirectory();
mypath=file.getAbsolutePath();
mypathOut=mypath+"/app_gaji/";//app_gaji
boolean mdir=createDirIfNotExists(mypathOut);
Log.d(TAG,"Status make directory "+mypathOut+":"+mdir);
txtnama=(EditText)findViewById(R.id.txtnama);
txtnama.setText(mypathOut);
txtnama.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
try {
Intent gintent = new Intent();
Uri mydir = Uri.parse(mypathOut);//default address :/storage/sdcard0/app_gaji
gintent.setDataAndType(mydir, "*/*");
//gintent.setType("image/*|application/pdf|audio/*");
//gintent.setType("image/*");//PDF image
gintent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(gintent, "Select Data"),PICK_IMAGE);
} catch (Exception e) {
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
Log.e(e.getClass().getName(), e.getMessage(), e);
}
}
});
+++++++++
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
String filePath="";
Uri selectedImageUri = null;
switch (requestCode) {
case PICK_IMAGE:
if (resultCode == Activity.RESULT_OK) { selectedImageUri = data.getData(); }
break;
}
if(selectedImageUri != null){
String A1 = selectedImageUri.getPath();
String B1 = getPath(selectedImageUri);
if (B1 != null) {
filePath = B1;
Log.v("filePath1",filePath);
} else if (A1 != null) {
filePath = A1;
Log.v("filePath2",filePath);
} else {
Toast.makeText(getApplicationContext(), "Unknown path", Toast.LENGTH_LONG).show();
Log.e("filePath", "Unknown path");
}
Log.v("PATHME","A1:"+A1+"#B1:"+B1+"#"+filePath);
if(filePath.indexOf(":")>0 || (filePath+"").length()<4){
txtnama.setText("");
Toast.makeText(getApplicationContext(), "Unknown path :"+filePath, Toast.LENGTH_LONG).show();
}
else{
txtnama.setText(filePath);
txtPath.setText("");
txtTime.setText("");
txtNote.setText("");
}
}
}
maka file akan terbuka dimanapun dia berada
Jangan Lupa permissionnya:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Tidak ada komentar:
Posting Komentar