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" >

    &lt;application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme" &gt;
        &lt;activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar" &gt;
            &lt;intent-filter&gt;
                &lt;action android:name="android.intent.action.MAIN" /&gt;
                &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
            &lt;/intent-filter&gt;
            &lt;/activity&gt;
        &lt;activity
            android:name=".Camera"
            android:label="@string/camera"&gt;
            &lt;uses-feature android:name="android.hardware.camera" android:required="false" /&gt;
            &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
        &lt;/activity&gt;
    
    &lt;/application&gt;
    

    </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" >
    
    &lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /&gt;
    &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
    
    &lt;application
    ....
    &lt;/application&gt;
    

    </manifest>


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2