2016-11-13 7 views
1

みんな私のアプリは、これは彼らが行ったように私は理解して、すべてで正常に動作しますが、ヌガーアンドロイドN FileUriExposedException

public void takepic(View view) { 

     TextView schtitle = (TextView) findViewById(R.id.Sitename); 
     String schname = schtitle.getText().toString(); 
      String[] tokens = schname.split(" "); 
      String timeStamp = new SimpleDateFormat("dd-MM-yyyy-HH-mm-ss").format(new Date()); 
      String imageFileName = tokens[0] + "-" + timeStamp + ".jpg"; 
      TextView myAwesomeTextView = (TextView)findViewById(R.id.filetext); 

      //in your OnCreate() method 
      myAwesomeTextView.setText(imageFileName); 
      Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);  


       File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); 
       String name = imageFileName; 
       File file = new File(path, name); 
       outputFileUri = Uri.fromFile(file); 
       intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri); 
       startActivityForResult(intent, TAKE_PICTURE); 


     } 

写真を撮るために、私は次のコードを使用し写真を撮るために株式のカメラを使用していますmarshmallowあなたは今ではパーミッションを必要とし、ファイルURIはもう使用できません

ノーガットで写真を撮る方法に関するサンプルコードは見つかりませんでした。誰かがこれを可能にするために自分のコードを変更する方法を教えてください?

は、すべてのヘルプは問題がファイルであるマーク・

+0

'FileProvider'を使用してください:https://github.com/ commonsguy/cw-omnibus/tree/master/Camera/FileProvider – CommonsWare

答えて

0

ちょうど参考のためにここにこれを引用します。

ファイルのuriでカメラの意図を使用して、アンドロイドのトレーニングセクションに撮影した画像を保存する方法に関する最新のドキュメントがあります。

https://developer.android.com/training/camera/photobasics.html

0
public void openShare(View view) { 
     // save bitmap to cache directory 
     try { 
      bitmap = ((BitmapDrawable) iv.getDrawable()).getBitmap(); 

      File cachePath = new File(getCacheDir(), "images"); 

      if (!cachePath.exists()) 
       cachePath.mkdirs(); 

      FileOutputStream stream = new FileOutputStream(cachePath + "/" + imageName); 
      bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream); 
      stream.close(); 

      shareImage(); 

     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 

    private void shareImage() { 
     File imagePath = new File(getCacheDir(), "images"); 
     File newFile = new File(imagePath, imageName); 
     Uri contentUri = MyFileProvider.getUriForFile(this, "com.example.kushaalsingla.contentsharingdemo", newFile); 

     if (contentUri != null) { 
      Intent shareIntent = new Intent(); 
      shareIntent.setAction(Intent.ACTION_SEND); 
      shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); // temp permission for receiving app to read this file 
      shareIntent.setDataAndType(contentUri, getContentResolver().getType(contentUri)); 
      shareIntent.putExtra(Intent.EXTRA_STREAM, contentUri); 
      startActivity(Intent.createChooser(shareIntent, "Choose an app")); 
     } 
    } 
##################
 <provider 
      android:name=".MyFileProvider" 
      android:authorities="com.example.kushaalsingla.contentsharingdemo" 
      android:grantUriPermissions="true" 
      android:exported="false"> 
      <meta-data 
       android:name="android.support.FILE_PROVIDER_PATHS" 
       android:resource="@xml/filepaths" /> 
     </provider> 
マニフェストに追加############# ##### filepaths.xml ##############
<?xml version="1.0" encoding="utf-8"?> 
<paths xmlns:android="http://schemas.android.com/apk/res/android"> 
    <cache-path name="shared_images" path="images/"/> 
</paths> 
関連する問題