的onActivityResult没有得到所谓的,而在Android的使用画廊 [英] onactivityresult not getting called while using Gallery in android

查看:194
本文介绍了的onActivityResult没有得到所谓的,而在Android的使用画廊的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的Andr​​oid应用程序中使用这个code开一家画廊。

I am opening a gallery in my Android Application using this code.

Intent intent = new Intent(Intent.ACTION_PICK, Media.EXTERNAL_CONTENT_URI);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivityForResult(intent, GALLERY);

它打开图片库,但,当我从那里的收盘也不过不叫选择任何图片的onActivityResult 方法。

方法是这里....

protected void onActivityResult(int requestCode, int resultCode, Intent data) {     


    Log.v(TAG, "requestCode = "+requestCode+" resultCode = "+resultCode);
    Log.v(TAG, "inside onActivityResult");

    if (requestCode == GALLERY || requestCode == CAMERA) {
        if (resultCode == RESULT_OK) 
        {
            Log.v(TAG, "inside onActivityResult OK ");
            Log.v("log_tag", "onactivity result: " + requestCode);
            if(requestCode == CAMERA)
            {
                Log.v(TAG, "inside onActivityResult Camera");
                 file = getTempFile(this.getParent());  
                 try {  
                    m_bmOCRBitmap = Media.getBitmap(getContentResolver(), Uri.fromFile(file) );

                    FileOutputStream out = new FileOutputStream(file);

                    int width = m_bmOCRBitmap.getWidth();
                    int height = m_bmOCRBitmap.getHeight();
                    if(width>height)
                    {
                        calwidth = (int)((width * 250)/height);
                        calheight = 250;
                    }
                    else
                    {
                        calheight = (int)((height * 200)/width);
                        calwidth = 200;
                    }

                    Log.v(TAG, "calwidth = "+calwidth+" calheight = "+calheight);
                    bitmap = Bitmap.createScaledBitmap(m_bmOCRBitmap, calwidth, calheight, true);                                                                   

                    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
                    productImage.setImageBitmap(bitmap);

                    } catch (FileNotFoundException e) {  
                      e.printStackTrace();  
                    } catch (IOException e) {  
                      e.printStackTrace();  
                    }  
            }
            else if(requestCode == GALLERY)
            {
                Log.v(TAG, "inside onActivityResult GALARY ");
                String selectedImagePath = getPath(data.getData());
                file = new File(selectedImagePath);                                     
                m_bmOCRBitmap = BitmapFactory.decodeFile(selectedImagePath);
                Log.v("log_tag", "selectedImagePath:" + selectedImagePath + ":" );
                Log.v("log", "first image : "+m_bmOCRBitmap);
                try {
                    FileOutputStream out = new FileOutputStream(file);
                    int width = m_bmOCRBitmap.getWidth();
                    int height = m_bmOCRBitmap.getHeight();
                    if(width>height)
                    {
                        calwidth = (int)((width * 250)/height);
                        calheight = 250;
                    }
                    else
                    {
                        calheight = (int)((height * 200)/width);
                        calwidth = 200;
                    }
                    bitmap = Bitmap.createScaledBitmap(m_bmOCRBitmap, calwidth, calheight, true);                                                                   

                    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
                    productImage.setImageBitmap(bitmap);

                } catch (Exception e) {
                    Log.v("log_tag", "Exception: " + e.toString());
                }
            }                           
        }
    }       
    super.onActivityResult(requestCode, resultCode, data);
}

而所谓的意图是警告

the Warning while called Intent is

01-04 12:21:06.434: D/PhoneWindow(367): couldn't save which view has focus because the focused view com.android.internal.policy.impl.PhoneWindow$DecorView@4054fb60 has no id.

请注意,我已经开始这项活动从Tabgoup活动的子活动。

please note that I have started this activity as child activity from Tabgoup Activity.

请建议我。谢谢你。

推荐答案

我父类像这样添加了这个方法。

I added this Method in Parent class like this

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    ProductImageActivity activity = (ProductImageActivity)getLocalActivityManager().getCurrentActivity();
    try {
        activity.onActivityResult(requestCode, resultCode, data,0);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

在我目前的类,我开始喜欢这个新的意图。

and in my current class I started new Intent like this.

Intent intent = new Intent(Intent.ACTION_PICK, Media.EXTERNAL_CONTENT_URI);
getParent().startActivityForResult(intent, GALLERY);

这篇关于的onActivityResult没有得到所谓的,而在Android的使用画廊的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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