Android:请求照片时出错?

发布于 2024-12-14 15:10:25 字数 4963 浏览 0 评论 0原文

我的应用程序遇到了一个我之前没有遇到过的问题。我想做的是允许用户选择使用意图从设备中拍摄照片。然后将该照片返回到调用活动,然后显示在图像视图中(目前......)。问题是昨天一切都对我有用,而今天(...没有对代码进行任何更改...)似乎什么也没做。看起来该应用程序几乎“挂起”了。不知道如何解决这个问题,甚至不知道如何解决这个问题的根本原因。如果有人有任何建议,请发布,这里是代码:

//---Pressing this button will allow for user to choose what photo should return---
    Button b2 = (Button) findViewById(R.id.btn_getPhotos);
    b2.setOnClickListener(new OnClickListener()
    {

        public void onClick(View arg0)
        {
            Intent i = new Intent(Intent.ACTION_GET_CONTENT);
            //Intent i = new Intent(Intent.ACTION_PICK);
            i.setType("image/*");

            //**Keep in mind after calling the StartActivityForResult() it seems to hang...**
            startActivityForResult(i, PIC_REQUEST);

        }

    });

这是 OnActivityResult():

 protected void onActivityResult(int requestCode, int resultCode, Intent data )
{   
    if (resultCode == Activity.RESULT_CANCELED)
    {
       //handles when camera was canceled...
       Toast.makeText(this, "Cancelled by user...", Toast.LENGTH_LONG).show();

    } 

    else if (requestCode == PIC_REQUEST) 
    {   
       Uri photoUri = data.getData();

       try 
       {
            Bitmap galleryPic = Media.getBitmap(getContentResolver(), photoUri);
            ImageView image = (ImageView) findViewById(R.id.currentPhoto); 
            image.setImageBitmap(galleryPic);

        } 
       catch (FileNotFoundException e) 
       {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 
       catch (IOException e) 
       {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

} 

最后但并非最不重要的是这里是警告/错误日志:

11-09 10:07:47.060: WARN/InputManagerService(142): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@407d13a8
11-09 10:07:56.330: WARN/ActivityThread(3957): Application king.chad.SDE is waiting for the debugger on port 8100...
11-09 10:08:06.250: WARN/ActivityManager(142): Launch timeout has expired, giving up wake lock!
11-09 10:08:06.320: WARN/ActivityManager(142): Activity idle timeout for ActivityRecord{40939988 king.chad.SDE/.MainActivity}

我想说我的问题在于日志的这一部分(基于其他日志)我研究过的论坛相关问题...),但我不确定:

11-09 10:08:23.090: WARN/InputManagerService(142): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@407f37e0 (uid=10022 pid=238)
11-09 10:08:45.890: WARN/InputManagerService(142): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@40ce5140

卸载应用程序,重新安装,调试,第二次运行时出现错误日志:

11-09 10:23:59.690: WARN/ActivityManager(142): No content provider found for: 
11-09 10:23:59.700: WARN/PackageParser(142): Unknown element under <manifest>: uses-library at /data/app/vmdl1692687349.tmp Binary XML file line #8
11-09 10:23:59.700: WARN/ActivityManager(142): No content provider found for: 
11-09 10:24:00.730: WARN/ResourceType(273): getEntry failing because entryIndex 1041 is beyond type entryCount 185
11-09 10:24:00.760: WARN/ResourceType(273): Failure getting entry for 0x7f020411 (t=1 e=1041) in package 0 (error -2147483647)
11-09 10:24:00.760: WARN/ResourceType(273): getEntry failing because entryIndex 1042 is beyond type entryCount 185
11-09 10:24:00.760: WARN/ResourceType(273): Failure getting entry for 0x7f020412 (t=1 e=1042) in package 0 (error -2147483647)
11-09 10:24:00.760: WARN/ResourceType(273): getEntry failing because entryIndex 1043 is beyond type entryCount 185
11-09 10:24:00.760: WARN/ResourceType(273): Failure getting entry for 0x7f020413 (t=1 e=1043) in package 0 (error -2147483647)
11-09 10:24:00.760: WARN/ResourceType(273): getEntry failing because entryIndex 1420 is beyond type entryCount 185
11-09 10:24:00.760: WARN/ResourceType(273): Failure getting entry for 0x7f02058c (t=1 e=1420) in package 0 (error -2147483647)
11-09 10:24:00.770: WARN/ResourceType(273): getEntry failing because entryIndex 223 is beyond type entryCount 185
11-09 10:24:00.770: WARN/ResourceType(273): Failure getting entry for 0x7f0200df (t=1 e=223) in package 0 (error -2147483647)
11-09 10:24:01.500: WARN/ActivityThread(5952): Application king.chad.SDE is waiting for the debugger on port 8100...
11-09 10:24:11.330: WARN/ActivityManager(142): Launch timeout has expired, giving up wake lock!
11-09 10:24:11.470: WARN/ActivityManager(142): Activity idle timeout for ActivityRecord{408a9dc8 king.chad.SDE/.MainActivity}
11-09 10:24:14.510: WARN/InputManagerService(142): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@407f37e0 (uid=10022 pid=238)
11-09 10:24:53.730: WARN/InputManagerService(142): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@4090b358

I am running into an issue with my app that I wasn't running into before hand. What I am trying to do is to allow the option for a user to pic a photo from the device using intents. Then return that photo back to the calling activity to then be displayed in an image view (for now...). Problem is that yesterday everything was working for me and today (...haven't changed anything with the code...) nothing seems to be doing anything at all. It almost seems like the app is "hanging". Not sure how to resolve this or even trouble shoot the root cause of this. If anyone has any suggestions please post, here is the code:

//---Pressing this button will allow for user to choose what photo should return---
    Button b2 = (Button) findViewById(R.id.btn_getPhotos);
    b2.setOnClickListener(new OnClickListener()
    {

        public void onClick(View arg0)
        {
            Intent i = new Intent(Intent.ACTION_GET_CONTENT);
            //Intent i = new Intent(Intent.ACTION_PICK);
            i.setType("image/*");

            //**Keep in mind after calling the StartActivityForResult() it seems to hang...**
            startActivityForResult(i, PIC_REQUEST);

        }

    });

Here is the OnActivityResult():

 protected void onActivityResult(int requestCode, int resultCode, Intent data )
{   
    if (resultCode == Activity.RESULT_CANCELED)
    {
       //handles when camera was canceled...
       Toast.makeText(this, "Cancelled by user...", Toast.LENGTH_LONG).show();

    } 

    else if (requestCode == PIC_REQUEST) 
    {   
       Uri photoUri = data.getData();

       try 
       {
            Bitmap galleryPic = Media.getBitmap(getContentResolver(), photoUri);
            ImageView image = (ImageView) findViewById(R.id.currentPhoto); 
            image.setImageBitmap(galleryPic);

        } 
       catch (FileNotFoundException e) 
       {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 
       catch (IOException e) 
       {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

} 

Last but not least here is the waring/error log:

11-09 10:07:47.060: WARN/InputManagerService(142): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@407d13a8
11-09 10:07:56.330: WARN/ActivityThread(3957): Application king.chad.SDE is waiting for the debugger on port 8100...
11-09 10:08:06.250: WARN/ActivityManager(142): Launch timeout has expired, giving up wake lock!
11-09 10:08:06.320: WARN/ActivityManager(142): Activity idle timeout for ActivityRecord{40939988 king.chad.SDE/.MainActivity}

I want to say that my problem lies within this section of the log (based on other forum related issues that I've researched...), but I'm not sure:

11-09 10:08:23.090: WARN/InputManagerService(142): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@407f37e0 (uid=10022 pid=238)
11-09 10:08:45.890: WARN/InputManagerService(142): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@40ce5140

Uninstalled app, re-installed, dubugged, error log on 2nd run:

11-09 10:23:59.690: WARN/ActivityManager(142): No content provider found for: 
11-09 10:23:59.700: WARN/PackageParser(142): Unknown element under <manifest>: uses-library at /data/app/vmdl1692687349.tmp Binary XML file line #8
11-09 10:23:59.700: WARN/ActivityManager(142): No content provider found for: 
11-09 10:24:00.730: WARN/ResourceType(273): getEntry failing because entryIndex 1041 is beyond type entryCount 185
11-09 10:24:00.760: WARN/ResourceType(273): Failure getting entry for 0x7f020411 (t=1 e=1041) in package 0 (error -2147483647)
11-09 10:24:00.760: WARN/ResourceType(273): getEntry failing because entryIndex 1042 is beyond type entryCount 185
11-09 10:24:00.760: WARN/ResourceType(273): Failure getting entry for 0x7f020412 (t=1 e=1042) in package 0 (error -2147483647)
11-09 10:24:00.760: WARN/ResourceType(273): getEntry failing because entryIndex 1043 is beyond type entryCount 185
11-09 10:24:00.760: WARN/ResourceType(273): Failure getting entry for 0x7f020413 (t=1 e=1043) in package 0 (error -2147483647)
11-09 10:24:00.760: WARN/ResourceType(273): getEntry failing because entryIndex 1420 is beyond type entryCount 185
11-09 10:24:00.760: WARN/ResourceType(273): Failure getting entry for 0x7f02058c (t=1 e=1420) in package 0 (error -2147483647)
11-09 10:24:00.770: WARN/ResourceType(273): getEntry failing because entryIndex 223 is beyond type entryCount 185
11-09 10:24:00.770: WARN/ResourceType(273): Failure getting entry for 0x7f0200df (t=1 e=223) in package 0 (error -2147483647)
11-09 10:24:01.500: WARN/ActivityThread(5952): Application king.chad.SDE is waiting for the debugger on port 8100...
11-09 10:24:11.330: WARN/ActivityManager(142): Launch timeout has expired, giving up wake lock!
11-09 10:24:11.470: WARN/ActivityManager(142): Activity idle timeout for ActivityRecord{408a9dc8 king.chad.SDE/.MainActivity}
11-09 10:24:14.510: WARN/InputManagerService(142): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@407f37e0 (uid=10022 pid=238)
11-09 10:24:53.730: WARN/InputManagerService(142): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@4090b358

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝色星空 2024-12-21 15:10:25

好吧,不知道为什么上面的代码不起作用,但我确实找到了解决这个问题的方法。经过大量阅读和搜索后,我发现这个问题实际上可能与我的代码无关,而是与我使用的设备有关。我最终改变了 startActivityForResult() 方法,将:

startActivityForResult(i, PIC_REQUEST);

... 更改为:

startActivityForResult(Intent.createChooser(i, "Select a photo"), PIC_REQUEST);

... 现在一切都很好。希望这对可能遇到同样问题的人有所帮助。

Well, not sure why the above code wasn't working, but I did find a work around for this. After much reading and searching I found that this issue may not actually be related to my code but the device that I was using. I ended up altering the startActivityForResult() method by changing:

startActivityForResult(i, PIC_REQUEST);

...to this:

startActivityForResult(Intent.createChooser(i, "Select a photo"), PIC_REQUEST);

...and now all is well. Hope this helps any of you that may encounter the same issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文