1

我正在尝试打开我的画廊并在我的 SD 卡中选择一个图像,但是当我单击按钮打开画廊时,它给了我强制关闭的错误,这是我的代码

 public void openGallery(int req_code){

        Intent intent = new Intent();
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_GET_CONTENT);
        startActivityForResult(Intent.createChooser(intent,"Select file to upload "), req_code);
   }

这是我的错误强制关闭..应用程序相机

在此处输入图像描述

日志猫

06-22 15:03:27.511: D/dalvikvm(179): GC_EXPLICIT freed <1K, 6% free 6439K/6791K, paused 6ms+6ms
06-22 15:03:28.893: I/Process(13882): Sending signal. PID: 13882 SIG: 9
06-22 15:03:29.041: W/InputManagerService(80): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@414c1a38
06-22 15:03:30.121: I/ActivityManager(80): Process com.android.gallery (pid 13882) has died.
06-22 15:03:30.121: W/WindowManager(80): Failure taking screenshot for (230x143) to layer 21015
06-22 15:03:30.765: I/ActivityManager(80): Starting: Intent { act=android.intent.action.PICK dat=content://media/external/images/media cmp=com.android.gallery/com.android.camera.ImageGallery } from pid 13692
06-22 15:03:30.771: W/WindowManager(80): Failure taking screenshot for (230x143) to layer 21015
06-22 15:03:30.878: I/ActivityManager(80): Start proc com.android.gallery for activity com.android.gallery/com.android.camera.ImageGallery: pid=13920 uid=10017 gids={1015, 1024, 1006, 2001, 3003}
06-22 15:03:32.221: W/ActivityManager(80): Activity destroy timeout for ActivityRecord{40e28e70 com.android.gallery/com.android.camera.ImageGallery}
06-22 15:03:33.151: D/AndroidRuntime(13920): Shutting down VM
06-22 15:03:33.151: W/dalvikvm(13920): threadid=1: thread exiting with uncaught exception (group=0x40014760)
06-22 15:03:33.241: E/AndroidRuntime(13920): FATAL EXCEPTION: main
06-22 15:03:33.241: E/AndroidRuntime(13920): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.gallery/com.android.camera.ImageGallery}: android.util.AndroidRuntimeException: You cannot combine custom titles with other title features
06-22 15:03:33.241: E/AndroidRuntime(13920):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1748)
06-22 15:03:33.241: E/AndroidRuntime(13920):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1764)
06-22 15:03:33.241: E/AndroidRuntime(13920):    at android.app.ActivityThread.access$1500(ActivityThread.java:122)
06-22 15:03:33.241: E/AndroidRuntime(13920):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1002)
06-22 15:03:33.241: E/AndroidRuntime(13920):    at android.os.Handler.dispatchMessage(Handler.java:99)
06-22 15:03:33.241: E/AndroidRuntime(13920):    at android.os.Looper.loop(Looper.java:132)
06-22 15:03:33.241: E/AndroidRuntime(13920):    at android.app.ActivityThread.main(ActivityThread.java:4025)
06-22 15:03:33.241: E/AndroidRuntime(13920):    at java.lang.reflect.Method.invokeNative(Native Method)
06-22 15:03:33.241: E/AndroidRuntime(13920):    at java.lang.reflect.Method.invoke(Method.java:491)
06-22 15:03:33.241: E/AndroidRuntime(13920):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
06-22 15:03:33.241: E/AndroidRuntime(13920):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
06-22 15:03:33.241: E/AndroidRuntime(13920):    at dalvik.system.NativeStart.main(Native Method)
06-22 15:03:33.241: E/AndroidRuntime(13920): Caused by: android.util.AndroidRuntimeException: You cannot combine custom titles with other title features
06-22 15:03:33.241: E/AndroidRuntime(13920):    at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:204)
06-22 15:03:33.241: E/AndroidRuntime(13920):    at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2339)
06-22 15:03:33.241: E/AndroidRuntime(13920):    at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:2546)
06-22 15:03:33.241: E/AndroidRuntime(13920):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:219)
06-22 15:03:33.241: E/AndroidRuntime(13920):    at android.app.Activity.setContentView(Activity.java:1780)
06-22 15:03:33.241: E/AndroidRuntime(13920):    at com.android.camera.ImageGallery.onCreate(ImageGallery.java:113)
06-22 15:03:33.241: E/AndroidRuntime(13920):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
06-22 15:03:33.241: E/AndroidRuntime(13920):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1712)
06-22 15:03:33.241: E/AndroidRuntime(13920):    ... 11 more
06-22 15:03:33.311: W/ActivityManager(80):   Force finishing activity com.android.gallery/com.android.camera.ImageGallery
06-22 15:03:33.401: W/WindowManager(80): Failure taking screenshot for (230x143) to layer 21020
4

4 回答 4

0

用这个 :

 button.setOnClickListener(new View.OnClickListener() {

        public void onClick(View arg) {
            Intent i = new Intent(Intent.ACTION_PICK,
                    android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            startActivityForResult(i, ACTIVITY_SELECT_IMAGE);
        }
    });

然后在 onActivityResult()

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    switch (requestCode) {
        case REQ_CODE_PICK_IMAGE:
            if (resultCode == RESULT_OK) {
                Uri selectedImage = data.getData();
                String[] filePathColumn = {MediaStore.Images.Media.DATA};

                Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
                cursor.moveToFirst();

                int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                String filePath = cursor.getString(columnIndex);
                cursor.close();
                //   Bitmap yourSelectedImage = BitmapFactory.decodeFile(filePath);
            }
    }
}
于 2012-06-22T10:06:40.647 回答
0

使用此代码,

Intent i = new Intent(Intent.ACTION_PICK,
                    android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
     startActivityForResult(i,REQUEST_CODE); 
于 2012-06-22T09:48:59.597 回答
0

用这个:

 Intent i = new Intent(Intent.ACTION_PICK,
           android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
 startActivityForResult(i, ACTIVITY_SELECT_IMAGE); 

然后在onActivityForResult中,调用intent.getData()获取Image的Uri。然后你需要从 ContentProvider 中获取 Image。

于 2012-06-22T09:51:02.030 回答
0

也许您在清单中忘记了这一点?

  <uses-permission android:name="android.permission.CAMERA" />
于 2012-06-22T12:18:11.463 回答