android-file

How to share *.txt file in android

主宰稳场 提交于 2019-12-04 08:29:31
I tried many ways but i can't do this . I have a *.txt file . i want share it via Bluetooth , wifi , email and ... . When i used this code i cant share the file: File file = new File(Environment.getExternalStorageDirectory(), "Email-Ghap/Emails.txt"); Intent sharingIntent = new Intent(Intent.ACTION_SEND); sharingIntent.setType("*/txt"); sharingIntent.putExtra(Intent.EXTRA_STREAM, file); startActivity(Intent.createChooser(sharingIntent, "share file with")); Totally i want this : when user clicked on share button and choose one email sender like Gmail for sharing . the file must be attached file

What is the maximum file path allowed in Android

北战南征 提交于 2019-12-04 07:09:41
The question here talks about file name length limit , I'm interested in the overall permitted path length (if it matters). There's this filesystems limits table here , though I'm not sure which applies to Android of which version. I tested with 1024 characters long path and it works in every device I tested on. I didn't go further up, maybe it mess up the sd card. I think, max file name length should be less than 128 and max file path length should be less than 1024 for Android. Again these are just my assumptions, they could be wrong. So be careful. Its not defined for Android as a whole-

How to write a file in external sd card and not in device storage?

折月煮酒 提交于 2019-12-04 04:08:11
问题 I tried this: public String getFilename() { File file = new File(Environment.getExternalStorageDirectory(), "Test2"); if (!file.exists()) { file.mkdirs(); } String uriSting = (file.getAbsolutePath() + "/" + "IMG_" + System.currentTimeMillis() + ".png"); return uriSting; } I tried changing the second line to: File file = new File("sdcard/Test2"); But still the directory is being created in device storage and not on external sd card. 回答1: You do not have arbitrary access to removable storage.

File.createTempFile() VS new File()

怎甘沉沦 提交于 2019-12-03 18:40:26
问题 In my app I added the possibility to add and save pictures for everyday day, represented by a Fragment . In order to save the picture on the SD card, I currently use the function File.createTempFile : File imageFile = File.createTempFile(imageFileName, MyApplication.JPEG_FILE_SUFFIX, MyApplication.getAlbumDir()); I actually also tried with the standard way: File imageFile = new File(MyApplication.getAlbumDir(), imageFileName + MyApplication.JPEG_FILE_SUFFIX); Both are working, but in my case

Intent ACTION_OPEN_DOCUMENT_TREE doesn't seem to return a real path to drive

混江龙づ霸主 提交于 2019-12-03 14:10:55
问题 I'm trying to read files from a USB storage device connected to my Google Pixel. I'm currently using this method to select the path of the drive so I can query it for its contents private static final String TAG = "MainActivity"; private static final int REQUEST_CHOOSE_DRIVE = 1; private TextView tv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tv = (TextView) findViewById(R.id.text); Intent i = new

Android, how to choose save file location?

喜夏-厌秋 提交于 2019-12-03 12:48:58
is there any solution how to choose the saving files location? maybe with the original file browser, to choose the destination? thank you! All you need is Android Directory Picker Maxim Better to save files with your app namespace: String extStorage = Environment.getExternalStorageState(); path = extStorage+"/Android/data/com.mydomain.myapp/"; It will be deleted when app gets uninstalled. Here is actually everything about data storing. http://developer.android.com/guide/topics/data/data-storage.html From the above link: If you're using API Level 7 or lower, use getExternalStorageDirectory() ,

Convert a file (<100Mo) in Base64 on Android

混江龙づ霸主 提交于 2019-12-03 11:12:07
I am trying to convert a file from the sdcard to Base64 but it seems the file is too big and i get an OutOfMemoryError. Here is my code : InputStream inputStream = null;//You can get an inputStream using any IO API inputStream = new FileInputStream(file.getAbsolutePath()); byte[] bytes; byte[] buffer = new byte[8192]; int bytesRead; ByteArrayOutputStream output = new ByteArrayOutputStream(); try { while ((bytesRead = inputStream.read(buffer)) != -1) { output.write(buffer, 0, bytesRead); } } catch (IOException e) { e.printStackTrace(); } bytes = output.toByteArray(); attachedFile = Base64

How to access /storage/emulated/0/

半世苍凉 提交于 2019-12-03 04:14:24
问题 I have written a code to record audio and save it to below file location. private String getFilename() { String filepath = Environment.getExternalStorageDirectory().getPath(); File file = new File(filepath, AUDIO_RECORDER_FOLDER); if (!file.exists()) { file.mkdirs(); } return (file.getAbsolutePath() + "/" + System.currentTimeMillis() + file_exts[currentFormat]); } In Logcat, it gives me a file location as /storage/emulated/0/AudioRecorder/1436854479696.mp4 I am not able to find this file

Database won't remove when uninstall the Android Application

依然范特西╮ 提交于 2019-12-03 02:36:46
问题 I have two major questions. Database won't delete when uninstall app. Downloaded files won't delete while unstable the app. There is a database in my android application. I create it by java class as follows. public DataBaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } public DataBaseHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version, DatabaseErrorHandler errorHandler) { super(context, name, factory, version,

File.createTempFile() VS new File()

五迷三道 提交于 2019-12-02 17:51:35
In my app I added the possibility to add and save pictures for everyday day, represented by a Fragment . In order to save the picture on the SD card, I currently use the function File.createTempFile : File imageFile = File.createTempFile(imageFileName, MyApplication.JPEG_FILE_SUFFIX, MyApplication.getAlbumDir()); I actually also tried with the standard way: File imageFile = new File(MyApplication.getAlbumDir(), imageFileName + MyApplication.JPEG_FILE_SUFFIX); Both are working, but in my case the first one is better than the second one because the function createTempFile adds a long random