私はまだAndroid開発の新人ですが、私が行くにつれて学習しています。もっと学習するためにクラスを取っています。私はいくつかのことをするアプリを持っているが、私が立ち往生している部分は、カメラと写真を撮っている。アイデアは、アプリケーションがカメラで写真を撮り、イメージをImageViewの「ソース」に設定するというものです。私はImageViewのビットマップを使用する場合、これをうまくやることができます。ただし、カメラで撮影して保存した後、ギャラリーから写真をアプリにインポートすることもできます。これは私が立ち往生している場所です。私は、このチュートリアルをどのように設定し、それを動作させるかについて、私に奇妙なエラーを与えてきました。 https://developer.android.com/training/camera/photobasics.html画像全体を保存できません。Android
「サムネイルを取得する」セクションまで到達することができましたが、それ以降は固まってしまいます。なぜ私の写真をどこの場所にも保存しないのか分かりません。
あり言うコードです:
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"></meta-data>
が、私は私がやったfile_paths
と呼ばxml
と呼ばれる私のres
フォルダ内にフォルダを作成し、そこにファイルを置くために必要なことに気づきました。
String mCurrentPhotoPath;
private File createImageFile() throws IOException
{
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName,
".jpg",
storageDir
);
mCurrentPhotoPath = image.getAbsolutePath();
return image;
}
static final int REQUET_TAKE_PHOTO = 1;
private void dispatchTakePictureIntent()
{
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null)
{
File photoFile = null;
try
{
photoFile = createImageFile();
}
catch (IOException ex)
{ }
if (photoFile != null)
{
Uri photoURI = FileProvider.getUriForFile(this, "com.example.fileprovider", photoFile);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
startActivityForResult(takePictureIntent, REQUET_TAKE_PHOTO);
}
}
}
private void galleryAddPic()
{
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
File f = new File(mCurrentPhotoPath);
Uri contentUri = Uri.fromFile(f);
mediaScanIntent.setData(contentUri);
this.sendBroadcast(mediaScanIntent);
}
マイManifest.xmlファイル:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.postvu">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
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" />
<uses-feature android:name="android.hardware.camera2"> </uses-feature>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.CAMERA"></uses-permission>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Main2Activity"></activity>
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.example.android.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"></meta-data>
</provider>
</application>
</manifest>
私は
<Paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="my_images" path="Android/data/com.example.android.postvu/files/pictures" />
</Paths>
を置く場所、それはすべてのヘルプは
おかげ
私の(関連)Javaコードを大幅に高く評価されています
タイトルのエラーはどこにありますか?エラーに関連するlogcatスタックトレースを投稿してください。プラスあなたのコードでは、あなたが例外、 'IOException'をミュートしていることがわかります:' catch(IOException ex){} '。これは何らかの理由でこの例外がスローされた場合、通知されることはないため、これは悪いことです。あなたの 'catch'ブロック内に' Log.e( "TAG"、 "error"、ex)を置きます。おそらくエラーはそこにあります。 – pleft
すみません。タイトルを変更するのを忘れた –
また、あなたが投稿したURLからサンプルアプリケーションをダウンロードし、あなたが何をやっているかを見て修正してください。 http://developer.android.com/shareables/training/PhotoIntentActivity.zip – pleft