android-file

How can I save my bitmap correctly for second time?

北城以北 提交于 2020-01-11 05:22:32
问题 I want to save my bitmap to cache directory. I use this code: try { File file_d = new File(dir+"screenshot.jpg"); @SuppressWarnings("unused") boolean deleted = file_d.delete(); } catch (Exception e) { // TODO: handle exception } imagePath = new File(dir+"screenshot.jpg"); FileOutputStream fos; try { fos = new FileOutputStream(imagePath); bitmap.compress(CompressFormat.JPEG, 100, fos); fos.flush(); fos.close(); } catch (FileNotFoundException e) { Log.e("GREC", e.getMessage(), e); } catch

How to get path to Storage directory in android

江枫思渺然 提交于 2020-01-11 04:17:09
问题 Is there any method to get /storage/ directory. I tried with Environment.getExternalStorageDirectory() but it returns /storage/emulated/0 i know i can use file.getParent() but for some reason i cant use that. I just want a straight path to /storage/ directory using some function... Thanks in advance. 回答1: You can't and should not access that directory normally . But it seems you need more control on storage locations are available to your device. For that you can use this, public List<String>

java.io.filenotfoundexception open failed eacces (permission denied) on device

馋奶兔 提交于 2020-01-09 19:08:20
问题 The following code which consists of downloading a file from a server and save it in the storage works fine when the device has an internal storage. But when I tried it with a device with no internal storage, only with external storage I get the following exception. java.io.filenotfoundexception open failed eacces (permission denied) public void downloadFile(String dlUrl, String dlName) { int count; HttpURLConnection con = null; InputStream is = null; FileOutputStream fos = null; try { URL

java.io.filenotfoundexception open failed eacces (permission denied) on device

泄露秘密 提交于 2020-01-09 19:03:47
问题 The following code which consists of downloading a file from a server and save it in the storage works fine when the device has an internal storage. But when I tried it with a device with no internal storage, only with external storage I get the following exception. java.io.filenotfoundexception open failed eacces (permission denied) public void downloadFile(String dlUrl, String dlName) { int count; HttpURLConnection con = null; InputStream is = null; FileOutputStream fos = null; try { URL

Create file from drawable to send with sendbird

邮差的信 提交于 2019-12-25 07:16:41
问题 I want use sendFileMessage in sendbird api. It need file value and I want use this file from drawable (or assets ). sendBird API this is snipped code from sendbird Hashtable<String, Object> info = Helper.getFileInfo(getActivity(), uri); final String path = (String) info.get("path"); File file = new File(path); String name = file.getName(); String mime = (String) info.get("mime"); int size = (Integer) info.get("size"); sendFileMessage(file, name, mime, size, "", new BaseChannel

How do I get the Assets path in an Android Studio project?

社会主义新天地 提交于 2019-12-25 04:23:20
问题 I feel like I'm missing something obvious, but I'm having trouble passing a CSV file to CSVReader , which takes a Reader in its constructor. I can use AssetManager.getAssets() , but that returns an InputStream and I can't get the file path from there, which the Reader constructor needs. My asset path is src/main/assets/dbsource/My.csv I need to get this into CSVReader csvReader = new CSVReader(new FileReader(csvPath)); I just can't get the path! Thanks. 回答1: It's difficult yo tell you what

Writing to an existing resource XML file in Android

那年仲夏 提交于 2019-12-25 03:28:12
问题 I am trying to write to an existing XML file in the /res/xml directory on an Android device. Two questions: 1) Are these files able to be overwritten? 2) If so, how can I obtain a handle to that file? I am trying this to no avail: FileOutputStream fos; try { fos = openFileOutput("/res/xml/scores.xml", Context.MODE_PRIVATE); fos.write(writer.toString().getBytes()); fos.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) {

I am not able to set multiple image in grid view?

这一生的挚爱 提交于 2019-12-25 03:08:29
问题 I am creating app in which 1.take photo from camera. 2.save its URI in database 3.using cursor and adaptor i retrieve image uri and sets in grid view. i am getting error as " error opening trace file: No such file or directory (2)" also i cant see any folder formed with name "my image" Main activity public class MainActivity extends ActionBarActivity { private static final int CAMERA_CAPTURE_IMAGE_REQUEST_CODE = 100; final int MEDIA_TYPE_IMAGE=2; Button click; ImageView image; Uri fileuri;

I am not able to set multiple image in grid view?

青春壹個敷衍的年華 提交于 2019-12-25 03:07:14
问题 I am creating app in which 1.take photo from camera. 2.save its URI in database 3.using cursor and adaptor i retrieve image uri and sets in grid view. i am getting error as " error opening trace file: No such file or directory (2)" also i cant see any folder formed with name "my image" Main activity public class MainActivity extends ActionBarActivity { private static final int CAMERA_CAPTURE_IMAGE_REQUEST_CODE = 100; final int MEDIA_TYPE_IMAGE=2; Button click; ImageView image; Uri fileuri;

Trying to list all folders/files from internal sdcard android but get a null

那年仲夏 提交于 2019-12-24 17:29:34
问题 I am trying to make a list of all the files in my external storage but always comes back null. if (Environment.getExternalStorageDirectory().exists()) { Log.i(FILE, "is not empty"); File[] files = Environment.getExternalStorageDirectory().listFiles(); for (File file : files) { Log.i("File ", file.getAbsolutePath()); } } How do I make it list all the files from the external directory I get an exception Caused by: java.lang.NullPointerException at com.example.sam.read.fragments.MyFragment