I can't create File.createTempFile.
-
Everything was a google class, but it doesn't work. Even ctrl+s ctrl+v did.
private File createImageFile() { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "Selfie_" + timeStamp + "_"; File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File image = null; try { image = File.createTempFile( imageFileName, /*prefix*/ ".jpg", /*suffix*/ storageDir /*directory*/ ); } catch (IOException e) { e.printStackTrace(); } // Save a file: path for use with ACTION_VIEW Intents test = storageDir.toString() + imageFileName ; if(image == null) mCurrentPhotoPath = "null"; else mCurrentPhotoPath = "file:" + image.getAbsolutePath(); return image; }
mCurrentPhotoPath = null
tets = /storage/sdcard0/PicturesSelfie_20151130_173814_
How so?
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.my.android.selfie" ><application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme" > <activity android:name=".MainActivity" android:label="@string/app_name" android:theme="@style/AppTheme.NoActionBar" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".Camera" android:label="@string/camera"> <uses-feature android:name="android.hardware.camera" android:required="false" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> </activity> </application>
</manifest>
-
It's likely that there's no permit in the manifest in his main theater. Try adding them:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.my.android.selfie" >
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <application .... </application>
</manifest>