Android: ошибка при запросе фотографий? - PullRequest
1 голос
/ 09 ноября 2011

У меня проблема с моим приложением, с которой я не сталкивался раньше.Я пытаюсь разрешить пользователю выбрать фотографию с устройства с помощью намерений.Затем верните эту фотографию обратно в функцию вызова, чтобы затем отобразить ее в режиме просмотра изображений (пока ...).Проблема в том, что вчера все работало на меня, а сегодня (... ничего не изменилось с кодом ...), кажется, ничего не происходит вообще.Похоже, приложение "висит".Не уверен, как решить эту или даже проблему устранить первопричину этого.Если у кого-то есть какие-либо предложения, пожалуйста, напишите, вот код:

//---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

Деинсталлированное приложение, переустановлено, перезаписано, журнал ошибок при 2-м запуске:

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

1 Ответ

0 голосов
/ 21 ноября 2011

Ну, не уверен, почему приведенный выше код не работает, но я нашел способ обойти это. После долгих чтений и поисков я обнаружил, что эта проблема может быть связана не с моим кодом, а с устройством, которое я использовал. Я закончил тем, что изменил метод startActivityForResult (), изменив:

startActivityForResult(i, PIC_REQUEST);

... на это:

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

... и теперь все хорошо. Надеюсь, что это поможет любому из вас, кто может столкнуться с той же проблемой.

...