android-file

set as default ringtone from raw folder programmatically in android

三世轮回 提交于 2019-12-24 16:42:50
问题 I tried this code its working fine to load the sound file to ringtones directory.I can manually select the sound from popup ..but its fail to set as default ringtone programmatically.plz help me to set the sound as default ringtone programmatically setContentView(R.layout.activity_main); String exStoragePath = Environment.getExternalStorageDirectory().getAbsolutePath(); path=(exStoragePath +"/media/alarms/"); // saveas(); saveas(RingtoneManager.TYPE_RINGTONE); } // In this method, we need to

Android RenameTo leaves empty file

牧云@^-^@ 提交于 2019-12-24 13:34:01
问题 Could you please help me. renameTo() leaves empty old file. So I see 2 files in file system with new name and old name. The size of old file is 0 . If I delete old file after renaming it says that file does not exist while staying in file system. An absolute path of directory is: /storage/sdcard0/DCIM/Camera My code: String dir = oldpath.substring(0, oldpath.lastIndexOf("/")); File directory = new File(dir); File from = new File(directory, oldfilename); File to = new File(directory, newname);

Android make my app files only play from inside the app

為{幸葍}努か 提交于 2019-12-24 11:07:40
问题 I created an app in which the client can record few conversations and store in external storage. The client must be able to transfer the files if needed. So I am storing the recorded files in external storage. But client don't want the files to be played from outside the app, (from sd card) or from music player. Is it possible? Please let me know. Is using internal storage is the only way to do it? 回答1: well this is not a programming question, but ... you have 2 options here, decide based on

I can't make sense Context.getFileStreamPath trying to test wether a file path exists?

杀马特。学长 韩版系。学妹 提交于 2019-12-23 17:37:57
问题 I have tried to make sense of the getFileStreamPath madness for some hours now. Could someone please explain how to test if a path = "shop/crates/fruits" exists? In an attempt to simplify the test i have broken the path in to segments. I thought i had it. But the test breaks when shop exists but there is no crates..Weird! Or is it? public static Boolean pathExists(String path, Context ctx) { Boolean result = false; String[] pathSegments = path.split("/"); String pathStr = ""; for(int i = 0;i

Picture file captured with camera intent empty for a while in onActivityResult

删除回忆录丶 提交于 2019-12-23 09:28:05
问题 I am having a very strange bug trying to take a picture via intent. Activity code (a little simplified): private void startCapture() throws IOException { // Create output file final File photoFile = makePhotoFile(); _photoPath = photoFile.getAbsolutePath(); Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); /* IMPORTANT NOTE TO READERS * As of Android N (which went out shortly after I posted this question), * you cannot use Uri.fromFile this way anymore. * You should use a

startActivityForResult not working in Android version 4.4 ( Kitkat version )

最后都变了- 提交于 2019-12-23 03:12:56
问题 Through my application the user can choose a file from the filemanager and process the choosen file ( Example: A PDF document ) for other steps like printing or to email. To do this I used the below code to display the intent, from which the user can choose a file from file-manager option. protected void showFileChooser(String title, String type) { Log.i(TAG, "FileChooserActivity showFileChooser(title,type)"); if (TextUtils.isEmpty(title)) title = getString(R.string.select_file); if

Is it possible to create and maintain a folder structure with files Using the Internal Storage

孤街醉人 提交于 2019-12-22 11:33:55
问题 I have studied the link below, but it doesn't answer my question. http://developer.android.com/guide/topics/data/data-storage.html#filesInternal If the answer to the question in the title is yes. Could someone please supply a simple example creating a subfolder and adding a file to that folder? And perhaps show how to read the file back from the sub folder? Or maybe tell me why the example below fails miserably Works now after changing file.mkdirs(); to file.getParentFile().mkdirs(); Se

how to create a file with world readable permission under subdirectory of files directory

做~自己de王妃 提交于 2019-12-18 11:47:44
问题 I need to create files under myapp/files/subdir with global permission in my application. I do this because I use external applications to open some files Using this FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_WORLD_READABLE); creates file only under files folder. Using File dir=new File(Constants.TASK_DIRECTORY); dir.mkdirs(); File file=new File(dir, FILENAME); file.createNewFile(); FileOutputStream fos=new FileOutputStream(file); creates files under subdirectories but with

How to get the internal and external sdcard path in android

青春壹個敷衍的年華 提交于 2019-12-18 03:09:04
问题 Most of the new android devices have an internal sdcard and an external sdcard. I want to make a file explorer app but I can't find out how to get the path to use in my app because File file = Environment.getExternalStorageDirectory(); just returns in most device /mnt/sdcard but there is another path for the other external sdcard like /storage1 or /storage2 . Any help appreciated. 回答1: How to get the internal and external sdcard path in android Methods to store in Internal Storage: File

Copy files from a folder of SD card into another folder of SD card

ⅰ亾dé卋堺 提交于 2019-12-17 22:34:26
问题 Is it possible to copy a folder present in sdcard to another folder present the same sdcard programmatically ?? If so, how to do that? 回答1: An improved version of that example: // If targetLocation does not exist, it will be created. public void copyDirectory(File sourceLocation , File targetLocation) throws IOException { if (sourceLocation.isDirectory()) { if (!targetLocation.exists() && !targetLocation.mkdirs()) { throw new IOException("Cannot create dir " + targetLocation.getAbsolutePath()