手机相册微信找不到相册照片了怎么办

Android拍照保存在系统相册与照片不显示解决方法-安卓教程-手机开发-壹聚教程网Android拍照保存在系统相册与照片不显示解决方法
现在几乎所有app应用都可以调用手机的照相功能了,但我在开始时碰到一个问题就是拍照之后在系统相册中找不到我拍照的照片怎么办?下面我来给各位同学一并分享一下。
系统已经有的东西,如果我们没有新的需求的话,直接调用是最直接的。下面讲讲调用系统相机拍照并保存图片和如何调用系统相册的方法。
首先看看调用系统相机的核心方法:
Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
&startActivityForResult(camera, CAMERA);
相机返回的数据通过下面的回调方法取得,并处理:
&protected void onActivityResult(int Code, int resultCode, Intent data) {
& super.onActivityResult(requestCode, resultCode, data);
& if(requestCode == CAMERA && resultCode == Activity.RESULT_OK && null != data){
&& String sdState=Environment.getExternalStorageState();
&& if(!sdState.equals(Environment.MEDIA_MOUNTED)){
&&& GameLog.log(Tag, &sd card unmount&);
&& new DateFormat();
&& String name= DateFormat.format(&yyyyMMdd_hhmmss&, Calendar.getInstance(Locale.CHINA))+&.jpg&;
&& Bundle bundle = data.getExtras();
&& //获取相机返回的数据,并转换为图片格式
&& Bitmap bitmap = (Bitmap)bundle.get(&data&);
&& FileOutputStream fout =
&& File file = new File(&/sdcard/pintu/&);
&& file.mkdirs();
&& String filename=file.getPath()+
&&& fout = new FileOutputStream(filename);
&&& pressFormat.JPEG, 100, fout);
(FileNotFoundException e) {
&&& e.printStackTrace();
&& }finally{
&&&& fout.flush();
&&&& fout.close();
&&& } catch (IOException e) {
&&&& e.printStackTrace();
&& //显示图片
下面是调用系统相册并取得照片的方法:
Intent picture = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(picture, PICTURE);
下面是相应的回调方法:
&protected void onActivityResult(int requestCode, int resultCode, Intent data) {
& super.onActivityResult(requestCode, resultCode, data);
& if(requestCode == CAMERA && resultCode == Activity.RESULT_OK && null != data){
&& Uri edImage = data.getData();
&& String[] filePathColumns={MediaStore.Images.Media.DATA};
&& Cursor c = this.getContentResolver().query(selectedImage, filePathColumns, null,null, null);
&& c.moveToFirst();
&& int columnIndex = c.getColumnIndex(filePathColumns[0]);
&& String picturePath= c.getString(columnIndex);
&& c.close();
&& //获取图片并显示
这样就完成了系统调用,很简单,但是有些朋友会碰到照片拍好了,在手机相册中发现照片不显示呀。
解决Android拍照保存在系统相册不显示的问题
MediaStore.Images.Media.insertImage(getContentResolver(), mBitmap, &&, &&);通过上面的那句代码就能插入到系统图库,这时候有一个问题,就是我们不能指定插入照片的名字,而是系统给了我们一个当前时间的毫秒数为名字,有一个问题郁闷了很久,我还是先把insertImage的源码贴出来吧
&&&&&&&&&&&& * Insert an image and create a thumbnail for it.
&&&&&&&&&&&& *
&&&&&&&&&&&& * @param cr The content resolver to use
&&&&&&&&&&&& * @param source The stream to use for the image
&&&&&&&&&&&& * @param title The name of the image
&&&&&&&&&&&& * @param description The description of the image
&&&&&&&&&&&& * @return The URL to the newly created image, or &code&null&/code& if the image failed to be stored
&&&&&&&&&&&& *&&&&&&&&&&&&& for any reason.
&&&&&&&&&&&& */
&&&&&&&&&&& public static final String insertImage(ContentResolver cr, Bitmap source,
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& String title, String description) {
&&&&&&&&&&&&&&& ContentValues values = new ContentValues();
&&&&&&&&&&&&&&& values.put(Images.Media.TITLE, title);
&&&&&&&&&&&&&&& values.put(Images.Media.DESCRIPTION, description);
&&&&&&&&&&&&&&& values.put(Images.Media.MIME_TYPE, &image/jpeg&);
&&&&&&&&&&&&&&& Uri url =
&&&&&&&&&&&&&&& String stringUrl =&&& /* value to be returned */
&&&&&&&&&&&&&&& try {
&&&&&&&&&&&&&&&&&&& url = cr.insert(EXTERNAL_CONTENT_URI, values);
&&&&&&&&&&&&&&&&&&& if (source != null) {
&&&&&&&&&&&&&&&&&&&&&&& OutputStream imageOut = cr.openOutputStream(url);
&&&&&&&&&&&&&&&&&&&&&&& try {
&&&&&&&&&&&&&&&&&&&&&&&&&&& pressFormat.JPEG, 50, imageOut);
&&&&&&&&&&&&&&&&&&&&&&& } finally {
&&&&&&&&&&&&&&&&&&&&&&&&&&& imageOut.close();
&&&&&&&&&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&&&&&&&&&& long id = ContentUris.parseId(url);
&&&&&&&&&&&&&&&&&&&&&&& // Wait until MINI_KIND thumbnail is generated.
&&&&&&&&&&&&&&&&&&&&&&& Bitmap miniThumb = Images.Thumbnails.getThumbnail(cr, id,
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& Images.Thumbnails.MINI_KIND, null);
&&&&&&&&&&&&&&&&&&&&&&& // This is for backward compatibility.
&&&&&&&&&&&&&&&&&&&&&&& Bitmap microThumb = StoreThumbnail(cr, miniThumb, id, 50F, 50F,
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& Images.Thumbnails.MICRO_KIND);
&&&&&&&&&&&&&&&&&&& } else {
&&&&&&&&&&&&&&&&&&&&&&& Log.e(TAG, &Failed to create thumbnail, removing original&);
&&&&&&&&&&&&&&&&&&&&&&& cr.delete(url, null, null);
&&&&&&&&&&&&&&&&&&&&&&& url =
&&&&&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&& } catch (Exception e) {
&&&&&&&&&&&&&&&&&&& Log.e(TAG, &Failed to insert image&, e);
&&&&&&&&&&&&&&&&&&& if (url != null) {
&&&&&&&&&&&&&&&&&&&&&&& cr.delete(url, null, null);
&&&&&&&&&&&&&&&&&&&&&&& url =
&&&&&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&& if (url != null) {
&&&&&&&&&&&&&&&&&&& stringUrl = url.toString();
&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&& return stringU
&&&&&&&&&&& }
上面方法里面有一个title,我刚以为是可以设置图片的名字,设置一下,原来不是,郁闷,哪位高手知道title这个字段是干嘛的,告诉下小弟,不胜感激!
当然Android还提供了一个插入系统相册的方法,可以指定保存图片的名字,我把源码贴出来吧
&&&&&&&&&&&& * Insert an image and create a thumbnail for it.
&&&&&&&&&&&& *
&&&&&&&&&&&& * @param cr The content resolver to use
&&&&&&&&&&&& * @param imagePath The path to the image to insert
&&&&&&&&&&&& * @param name The name of the image
&&&&&&&&&&&& * @param description The description of the image
&&&&&&&&&&&& * @return The URL to the newly created image
&&&&&&&&&&&& * @throws FileNotFoundException
&&&&&&&&&&&& */
&&&&&&&&&&& public static final String insertImage(ContentResolver cr, String imagePath,
&&&&&&&&&&&&&&&&&&& String name, String description) throws FileNotFoundException {
&&&&&&&&&&&&&&& // Check if file exists with a FileInputStream
&&&&&&&&&&&&&&& FileInputStream stream = new FileInputStream(imagePath);
&&&&&&&&&&&&&&& try {
&&&&&&&&&&&&&&&&&&& Bitmap bm = BitmapFactory.decodeFile(imagePath);
&&&&&&&&&&&&&&&&&&& String ret = insertImage(cr, bm, name, description);
&&&&&&&&&&&&&&&&&&& bm.recycle();
&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&& } finally {
&&&&&&&&&&&&&&&&&&& try {
&&&&&&&&&&&&&&&&&&&&&&& stream.close();
&&&&&&&&&&&&&&&&&&& } catch (IOException e) {
&&&&&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&& }
&&&&&&&&&&& }
啊啊,贴完源码我才发现,这个方法调用了第一个方法,这个name就是上面方法的title,晕死,这下更加郁闷了,反正我设置title无效果,求高手为小弟解答,先不管了,我们继续往下说
上面那段代码插入到系统相册之后还需要发条广播
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse(&file://&+ Environment.getExternalStorageDirectory())));&
上面那条广播是扫描整个sd卡的广播,如果你sd卡里面东西很多会扫描很久,在扫描当中我们是不能访问sd卡,所以这样子用户体现很不好,用过微信的朋友都知道,微信保存图片到系统相册并没有扫描整个SD卡,所以我们用到下面的方法
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);&&
&Uri uri = Uri.fromFile(new File(&/sdcard/image.jpg&));&&
&intent.setData(uri);&&
&mContext.sendBroadcast(intent);&
或者用MediaScannerConnection
final MediaScannerConnection msc = new MediaScannerConnection(mContext, new MediaScannerConnectionClient() {&&
& public void onMediaScannerConnected() {&&
&& msc.scanFile(&/sdcard/image.jpg&, &image/jpeg&);&&
& public void onScanCompleted(String path, Uri uri) {&&
&& Log.v(TAG, &scan completed&);&&
&& msc.disconnect();&&
也行你会问我,怎么获取到我们刚刚插入的图片的路径?呵呵,这个自有方法获取,insertImage(ContentResolver cr, Bitmap source,String title, String description),这个方法给我们返回的就是插入图片的Uri,我们根据这个Uri就能获取到图片的绝对路径
private& String getFilePathByContentResolver(Context context, Uri uri) {
&&if (null == uri) {
&&&&&&& Cursor c = context.getContentResolver().query(uri, null, null, null, null);
&&&&&&& String filePath& =
&&&&&&& if (null == c) {
&&&&&&&&&&& throw new IllegalArgumentException(
&&&&&&&&&&&&&&&&&&& &Query on & + uri + & returns null result.&);
&&&&&&& try {
&&&&&&&&&&& if ((c.getCount() != 1) || !c.moveToFirst()) {
&&&&&&&&&&& } else {
&&&&&&&&&&& &filePath = c.getString(
&&&&&&&&&&& &&&c.getColumnIndexOrThrow(MediaColumns.DATA));
&&&&&&&&&&& }
&&&&&&& } finally {
&&&&&&&&&&& c.close();
&&&&&&& return fileP
根据上面的那个方法获取到的就是图片的绝对路径
上一页: &&&&&下一页:相关内容不见了智能手机照片怎么办
您当前的位置: &
& 不见了智能手机照片怎么办
点击图片查看大图
不见了智能手机照片怎么办&
最小起订量:
供货总量:
发货期限:
自买家付款之日起 3 天内发货
发布时间:
10:39:15&&有效期至:长期有效
更新时间:
就在上周,天盾数据恢复专家就接到了用户的的咨询电话,原来客户在周末出去玩的时候,用手机拍了照片,因为像素能满足要求,就没有带相机。但是回家之后,和孩子在一起观看照片的时候,发现有几张照片拍的不好,智能手机数据恢复软件大师:/soft/appid/17810.html就想删掉,但是孩子手快,一不小心按到了全部删除,一眨眼照片就没了。这个时候,还能否把手机里的照片找回呢?用户口气十分心急,看来照片对客户很是重要。
答案是肯定的,天我们用数据恢复软件就可以搞定一般来说,当我们错误地删除了手机照片的时候,并不意味着这些照片会直接从手机存储卡之内丢失。类似的情况也发生在传统的硬盘、U盘等存储设备上。这些被删除之后的照片数据会依然保存在手机存储卡上,采用专业的数据恢复软件,经过一定的数据分析定位和 处理过程,即可顺利地将之全部还原出来。
以手机照片恢复处理为例,我们可以选择具备较强数据恢复能力的顶尖手机数据恢复软件作为恢复工具。顶尖手机数据恢复软件是一款全面的数据恢复工具,可以完全支持包括手机、电脑、平板电脑以及MP3等具备存储设备的数据恢复处理。
u盘数据恢复软件:/softview/SoftView_97812.html
格式化恢复软件:/softview/SoftView_99821.html
顶尖手机数据恢复软件本身拥有更为先进的全兼容核心体系,能够有效地针对硬盘、手机、数码相机等具备存储设备的数据提供全面恢复处理。顶尖手机数据恢复软件的恢复核心采用了超线程扫描和恢复处理技术,深度扫描存储设备,极速恢复丢失数据。在具体的数据恢复操作过程当中,顶尖手机数据恢复软件真正意义上实现了极简恢复,通过简单的选择文件原位置&&扫描&&勾选恢复三个步骤即可完成恢复。本产品网址:/b2b/sgyugqw/sell/itemid-.html我的手机相册不见了,怎么办。_百度知道

我要回帖

更多关于 手机拍照在相册找不到 的文章

 

随机推荐