android-file

Null pointer Exception on file- URI?

二次信任 提交于 2019-12-17 20:37:09
问题 In my app a capture button is there to capture an image using device camera,so I have used a method captureImage() on the click event of that button.When I click the button a null pointer exception is thrown.I could not understand how this happens Can anyone help? Thanks in advance! capture button on on Create () method photoButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { /* Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION

Simple mediaplayer play mp3 from file path?

╄→尐↘猪︶ㄣ 提交于 2019-12-17 06:12:25
问题 I have a very simple mediaplayer that play background. It calls file from the apk, but I want it to play from any directory like as music or sdcard. Here are my codes: private MediaPlayer mpintro; . . mpintro = MediaPlayer.create(this, R.raw.intro); mpintro.setLooping(true); mpintro.start(); 回答1: It works like this: mpintro = MediaPlayer.create(this, Uri.parse(Environment.getExternalStorageDirectory().getPath()+ "/Music/intro.mp3")); mpintro.setLooping(true); mpintro.start(); It did not work

Simple mediaplayer play mp3 from file path?

痴心易碎 提交于 2019-12-17 06:12:02
问题 I have a very simple mediaplayer that play background. It calls file from the apk, but I want it to play from any directory like as music or sdcard. Here are my codes: private MediaPlayer mpintro; . . mpintro = MediaPlayer.create(this, R.raw.intro); mpintro.setLooping(true); mpintro.start(); 回答1: It works like this: mpintro = MediaPlayer.create(this, Uri.parse(Environment.getExternalStorageDirectory().getPath()+ "/Music/intro.mp3")); mpintro.setLooping(true); mpintro.start(); It did not work

Dynamically read files from Sdcard

人走茶凉 提交于 2019-12-14 04:02:55
问题 Guys i have a text file in sdcard i need to read that file. Below is my code to read files: File f = new File(Environment.getExternalStorageDirectory()+"/f1.txt"); fileIS = new FileInputStream(f); BufferedReader buf = new BufferedReader(new InputStreamReader(fileIS)); String readString = new String(); //just reading each line and pass it on the debugger while((readString = buf.readLine())!= null){ textdata.setText(readString); Log.d("line: ", readString); } } catch (FileNotFoundException e) {

Function to update a photo in ContactsContract

一世执手 提交于 2019-12-14 02:28:38
问题 I try to update a photo in ContactsContract with a function who take the id of the contact and the uri of the picture but it seem it's not working (and my function return true ). I really don't understand because the code look good. It seem it's working when the contact have already a photo... This is my function : boolean updatePhoto(String idStr, String uri){ if (uri != null) { ArrayList<ContentProviderOperation> ops = new ArrayList<>(); File imgFile = new File(uri.replace("file://", ""));

Android How to get the root directory from a file (path)

眉间皱痕 提交于 2019-12-13 06:45:34
问题 How do I get the root directory of any path. If i have file path /storage/emulated/0/Android/media/com.google.android.talk/Ringtones/, what is the best way for me to return the root directory "storage". Is the file path always in "/" format, is that safe to split the path based on the character "/" or is there a built in function that I can call? I need to create a method to return the root files of all the audio files on the android phone. Here are some paths that I have and I want to start

context.openFileInput() returning null when trying to access a stored file

删除回忆录丶 提交于 2019-12-12 16:42:39
问题 Currently, I have the following code for saving a Web Archive and then getting it as a FileInputStream. However, the channel within webContent remains null and a FileNotFoundException is thrown: // Save the Web Archive once loading is finished String path = context.getFilesDir().getAbsolutePath() + File.separator + WEB_PREFIX + postId; webView.saveWebArchive(path); FileInputStream webContent = null; try { webContent = context.openFileInput(WEB_PREFIX + postId); } catch (FileNotFoundException

Android File Provider Illegal Argument Exception

安稳与你 提交于 2019-12-12 09:33:08
问题 I am using file provider to save photo to a given destination. I get: java.lang.IllegalArgumentException: Missing android.support.FILE_PROVIDER_PATHS meta-data while trying to open activity to capture image from camera. My manifest.xml file: <provider android:name="android.support.v4.content.FileProvider" android:authorities="com.example" android:exported="false" android:grantUriPermissions="true"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/paths" />

Trying to get a file path to a public folder on android device and get its content

二次信任 提交于 2019-12-12 05:17:26
问题 I am looking to get the file path of a folder and then get its content. The folders are a public folder that you can access by just connecting the device into the computer. How do I go about getting a the file path to get access to these public folders and then get all its content? So once I connect my computer to the device these are the folders I see and there is one that says "Folder to get items from" and I can't seem to figure what the file path is in order to get access to its content .

why get java.lang.IllegalStateException: Unable to create directory error?

吃可爱长大的小学妹 提交于 2019-12-12 04:36:47
问题 I use DownloadManager class to download a file in android and this is my code for download: Uri downloadUri = Uri.parse(urlString); DownloadManager.Request request = new DownloadManager.Request(downloadUri); request.setDescription(des).setTitle(titleAudio).setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED). setDestinationInExternalPublicDir( "/my file name/" , titleAudio + String.valueOf(colForUrl) + pasvand); long id = downloadManager.enqueue(request);