android mediastore.images.media.insertimage,android – MediaStore.Images.Media.insertImage有时会返回null...
我遇到了奇怪的问题,在调用MediaStore.Images.Media.insertImage时,它有时会返回null uri,但我发现它可以运行一两次,我找不到它的规则.请给予帮助,非常感谢!logcat是:06-18 11:09:24.559: E/MediaStore(13050): Thumbnail is not generated in query() with blockingUr
我遇到了奇怪的问题,在调用MediaStore.
Images.Media.insertImage时,它有时会返回null uri,但我发现它可以运行一两次,我找不到它的规则.
请给予帮助,非常感谢!
logcat是:
06-18 11:09:24.559: E/MediaStore(13050): Thumbnail is not generated in query() with blockingUri. Return null!
06-18 11:09:24.567: E/MediaStore(13050): Failed to insert image
06-18 11:09:24.567: E/MediaStore(13050): java.lang.NullPointerException
06-18 11:09:24.567: E/MediaStore(13050): at android.provider.MediaStore$Images$Media.StoreThumbnail(MediaStore.java:755)
06-18 11:09:24.567: E/MediaStore(13050): at android.provider.MediaStore$Images$Media.insertImage(MediaStore.java:824)
06-18 11:09:24.567: E/MediaStore(13050): at net.blogjava.mobile.camera.Main.onActivityResult(Main.java:57)
06-18 11:09:24.567: E/MediaStore(13050): at android.app.Activity.dispatchActivityResult(Activity.java:4649)
06-18 11:09:24.567: E/MediaStore(13050): at android.app.ActivityThread.deliverResults(ActivityThread.java:2990)
06-18 11:09:24.567: E/MediaStore(13050): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3037)
06-18 11:09:24.567: E/MediaStore(13050): at android.app.ActivityThread.access$1100(ActivityThread.java:127)
06-18 11:09:24.567: E/MediaStore(13050): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1191)
06-18 11:09:24.567: E/MediaStore(13050): at android.os.Handler.dispatchMessage(Handler.java:99)
06-18 11:09:24.567: E/MediaStore(13050): at android.os.Looper.loop(Looper.java:137)
06-18 11:09:24.567: E/MediaStore(13050): at android.app.ActivityThread.main(ActivityThread.java:4512)
06-18 11:09:24.567: E/MediaStore(13050): at java.lang.reflect.Method.invokeNative(Native Method)
06-18 11:09:24.567: E/MediaStore(13050): at java.lang.reflect.Method.invoke(Method.java:511)
06-18 11:09:24.567: E/MediaStore(13050): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:982)
06-18 11:09:24.567: E/MediaStore(13050): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:749)
06-18 11:09:24.567: E/MediaStore(13050): at dalvik.system.NativeStart.main(Native Method)
我的代码是:
import java.io.File;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Toast;
public class Main extends Activity implements OnClickListener
{
public ImageView imageView;
private ImageView ivFocus;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btnTakePicture = (Button) findViewById(R.id.btnTakePicture);
btnTakePicture.setOnClickListener(this);
imageView = (ImageView) findViewById(R.id.imageview);
ivFocus = new ImageView(this);
Toast.makeText(this, "onCreate", Toast.LENGTH_LONG).show();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == 1)
{
if (resultCode == Activity.RESULT_OK)
{
Bitmap cameraBitmap;
try {
if(data != null)
{
cameraBitmap = (Bitmap) data.getExtras().get("data");
}
else
{
cameraBitmap = BitmapFactory.decodeFile("/sdcard/1test.jpg");
}
imageView.setImageBitmap(cameraBitmap);
ContentResolver cr = getContentResolver();
String ret = MediaStore.Images.Media.insertImage(cr, cameraBitmap, "my_pic", "my picture");
setTitle(ret);
} catch (Exception e) {
Toast.makeText(this, e.getClass()+":"+e.getMessage(), Toast.LENGTH_LONG).show();
}
}
}
super.onActivityResult(requestCode, resultCode, data);
}
@Override
public void onClick(View view)
{
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
//Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File("/sdcard/1test.jpg")));
startActivityForResult(intent, 1);
}
}
更多推荐
所有评论(0)