对话屏幕例如WhatsApp头像对话框屏幕 [英] Dialog Screen Like WhatsApp Profile Photo Dialog Screen

查看:808
本文介绍了对话屏幕例如WhatsApp头像对话框屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以为相机和画廊都一样喜欢WHATS APP编辑个人资料。[链接] <共同选择器href=\"http://stackoverflow.com/questions/23825289/i-want-to-make-a-dialog-screen-like-whatsapp-profile-photo-dialog-screen\">I想使对话屏幕例如WhatsApp头像对话框屏幕 ......但在的onActivityResult(在发生问题)......我们不能让能之间无论我们从图库中选择图片来区分或者我们从拍摄的图像相机?那么如何才能使他们之间的的onActivityResult()区分?任何解决方案? plz帮助我,如果你有!!

We can create common chooser for camera and gallery both same as like WHATS APP EDIT PROFILE .. [link]I want to make a Dialog Screen Like WhatsApp Profile Photo Dialog Screen ... but the problem is occurred at onActivityResult() ..we can't make able to differentiate between Whether we choose image from gallery Or We captured image from Camera? so how can we make differentiate between them at onActivityResult()? Any Solutions? plz Help me if you have!!

推荐答案

如何启动一个意图无论从画廊或相机或注册到浏览文件系统的任何应用程序中选择图像。

How to launch a single Intent to select images from either the Gallery or the Camera, or any application registered to browse the filesystem.

而不是意图的选项列表创建对话框,它可能更好,以获得进入图形图标和各种照相机的短名称,画廊,甚至第三方使用Intent.createChooser文件系统浏览器的应用程序,如天文,等等。

Rather than creating a Dialog with a list of Intent options, it is much better to use Intent.createChooser in order to get access to the graphical icons and short names of the various 'Camera', 'Gallery' and even Third Party filesystem browser apps such as 'Astro', etc.

本介绍如何使用标准的选择器意图并增加额外的意图了这一点。

This describes how to use the standard chooser-intent and add additional intents to that.

private Uri outputFileUri;

private void openImageIntent() {

// Determine Uri of camera image to save.
final File root = new File(Environment.getExternalStorageDirectory() + File.separator + "MyDir" + File.separator);
root.mkdirs();
final String fname = Utils.getUniqueImageFilename();
final File sdImageMainDirectory = new File(root, fname);
outputFileUri = Uri.fromFile(sdImageMainDirectory);

    // Camera.
    final List<Intent> cameraIntents = new ArrayList<Intent>();
    final Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    final PackageManager packageManager = getPackageManager();
    final List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0);
    for(ResolveInfo res : listCam) {
        final String packageName = res.activityInfo.packageName;
        final Intent intent = new Intent(captureIntent);
        intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
        intent.setPackage(packageName);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
        cameraIntents.add(intent);
    }

    // Filesystem.
    final Intent galleryIntent = new Intent();
    galleryIntent.setType("image/*");
    galleryIntent.setAction(Intent.ACTION_GET_CONTENT);

    // Chooser of filesystem options.
    final Intent chooserIntent = Intent.createChooser(galleryIntent, "Select Source");

    // Add the camera options.
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[]{}));

    startActivityForResult(chooserIntent, YOUR_SELECT_PICTURE_REQUEST_CODE);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    if(resultCode == RESULT_OK)
    {
        if(requestCode == YOUR_SELECT_PICTURE_REQUEST_CODE)
        {
            final boolean isCamera;
            if(data == null)
            {
                isCamera = true;
            }
            else
            {
                final String action = data.getAction();
                if(action == null)
                {
                    isCamera = false;
                }
                else
                {
                    isCamera = action.equals(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                }
            }

            Uri selectedImageUri;
            if(isCamera)
            {
                selectedImageUri = outputFileUri;
            }
            else
            {
                selectedImageUri = data == null ? null : data.getData();
            }
        }
    }
}

或为完整的示例例如检查

Or for complete sample example check this

这篇关于对话屏幕例如WhatsApp头像对话框屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆