2012-03-21 3 views
0

Я делаю словарь для телефонов и планшетов для Android. Я сделал файл на моей учетной записи разработчика, и я работаю как шарм на телефоне. Когда я пытаюсь запустить точно такой же код на моей вкладке галактики Samsung 10.1, он застревает.Скачать файлы расширений на планшете

 if (!expansionFilesDelivered()) { 

     try { 
        Intent launchIntent = SampleDownloaderActivity.this.getIntent(); 
        Intent intentToLaunchThisActivityFromNotification = new Intent(SampleDownloaderActivity.this, SampleDownloaderActivity.this.getClass()); 
        intentToLaunchThisActivityFromNotification.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); 
        intentToLaunchThisActivityFromNotification.setAction(launchIntent.getAction()); 

        if (launchIntent.getCategories() != null) { 
         for (String category : launchIntent.getCategories()) { 
          intentToLaunchThisActivityFromNotification.addCategory(category); 
         } 
        } 

        // Build PendingIntent used to open this activity from 
        // Notification 
        PendingIntent pendingIntent = PendingIntent.getActivity(SampleDownloaderActivity.this, 0, intentToLaunchThisActivityFromNotification, PendingIntent.FLAG_UPDATE_CURRENT); 
        // Request to start the download 

        NotificationManager nm = (NotificationManager) getApplicationContext().getSystemService(NOTIFICATION_SERVICE); 

        int startResult = DownloaderClientMarshaller.startDownloadServiceIfRequired(this, pendingIntent, SampleDownloaderService.class); 

        if (startResult != DownloaderClientMarshaller.NO_DOWNLOAD_REQUIRED) { 
         // The DownloaderService has started downloading the files, 
         // show progress 
         initializeDownloadUI(); 

         return; 

       } // otherwise, download not needed so we fall through to 
        // starting the movie 
     } catch (NameNotFoundException e) { 
      Log.e(LOG_TAG, "Cannot find own package! MAYDAY!"); 
      e.printStackTrace(); 
     } 

    } 

Он поставляется с этим исключением:

03-21 15:24:45.940: I/ApplicationPackageManager(17750): cscCountry is not German : NEE 
03-21 15:24:46.000: D/dalvikvm(17750): GC_CONCURRENT freed 347K, 7% free 6569K/7047K, paused 3ms+3ms 
03-21 15:24:47.280: E/Environment(17750): getExternalStorageState/mnt/sdcard 
03-21 15:24:47.370: W/LVLDL(17750): Exception for main.2.dk.letsoftware.KFEnglish.obb: java.lang.NoSuchMethodError: android.app.Notification$Builder.setProgress 
03-21 15:37:29.480: I/ApplicationPackageManager(17750): cscCountry is not German : NEE 
03-21 15:37:29.950: D/dalvikvm(17750): GC_CONCURRENT freed 217K, 5% free 6768K/7111K, paused 3ms+6ms 
03-21 15:37:30.650: E/Environment(17750): getExternalStorageState/mnt/sdcard 
03-21 15:37:30.760: W/LVLDL(17750): Exception for main.2.dk.letsoftware.KFEnglish.obb: java.lang.NoSuchMethodError: android.app.Notification$Builder.setProgress 
03-21 15:37:40.410: D/CLIPBOARD(17750): Hide Clipboard dialog at Starting input: finished by someone else... ! 
03-21 15:40:24.870: D/dalvikvm(17750): GC_EXPLICIT freed 239K, 7% free 6619K/7111K, paused 2ms+2ms 
03-21 15:41:51.140: I/ApplicationPackageManager(17750): cscCountry is not German : NEE 
03-21 15:41:51.560: E/Environment(17750): getExternalStorageState/mnt/sdcard 
03-21 15:41:51.660: W/LVLDL(17750): Exception for main.2.dk.letsoftware.KFEnglish.obb: java.lang.NoSuchMethodError: android.app.Notification$Builder.setProgress 

Я понятия не имею, почему я не буду скачать. Перед тем, как появится этот экран, он показывает размер файла, который я знаю, что я могу его использовать.

, пожалуйста, помогите мне, спасибо

+0

Когда вы говорите «он застрял», где он находится в отладке? Есть ли очевидный момент неудачи? – HaemEternal

+0

он проходит весь путь, но он никогда не загружается. Он просто продолжает показывать экран с «началом». Когда я затем нажимаю уведомление, он снова начинается снова. – Fuglsang

+0

FYI Если бы вы использовали «Lint» над своим проектом, он бы выбрал это. – Blundell

ответ

3

У меня такая же проблема. У меня есть преимущество:

Если вы ищете «setProgress», вы можете увидеть, что он существует в файле «V11CustomNotification», который предназначен (я думаю) для API11 +, который включает в себя соты для планшетов.

«setProgress» доступен только для API14 +, поэтому вы получаете исключение.

теперь вопрос в том, как это исправить ...

есть 2 способа: 1.Check если метод существует на «CustomNotificationFactory», а если нет, то возвращает экземпляр V3CustomNotification.

2. замените код, вызывающий метод setProgress, чтобы он работал для API11..13 (в том числе).

В любом случае, пожалуйста, сообщите нам, что вы сделали (точно), чтобы мы могли извлечь из этого все преимущества.

я выбрал исправить # 1, так как это проще и я так и не удалось с # 2 (я пробовал): редактировать файл, и использовать там следующий код:

static public DownloadNotification.ICustomNotification createCustomNotification() 
{ 
    try 
    { 
    final Class<?> notificationBuilderClass = Class.forName("android.app.Notification$Builder"); 
    notificationBuilderClass.getDeclaredMethod("setProgress", new Class[] {Integer.TYPE, Integer.TYPE, Boolean.TYPE}); 
    return new V11CustomNotification(); 
    } 
    catch (final Exception e) 
    { 
    return new V3CustomNotification(); 
    } 
} 
0

Я вижу такой же провал в Toshiba Thrive. Ответ от разработчика «Android-разработчика». В основном это означает, что download_library не был протестирован на устройстве V11.

1

Я решил проблему. Я ТОК этот код и скопировал вместо кода там, где в CustomNotificationFactory

static public DownloadNotification.ICustomNotification createCustomNotification() 
{ 
    try 
    { 
    final Class<?> notificationBuilderClass = Class.forName("android.app.Notification$Builder"); 
    notificationBuilderClass.getDeclaredMethod("setProgress", new Class[] {Integer.TYPE, Integer.TYPE, Boolean.TYPE}); 
    return new V11CustomNotification(); 
    } 
    catch (final Exception e) 
    { 
    return new V3CustomNotification(); 
    } 
} 

Я отлично работает: D спасибо: D

2

Я просто добавил несколько строк кода в com.google. android.vending.expansion.downloader.impl .V11CustomNotification класс:

public class V11CustomNotification implements DownloadNotification.ICustomNotification { 
// ... 
    boolean hasSetProgressFunction = false; // Added 
    boolean hasCheckedForSetProgressFunction = false; // Added 

    public void CheckForFunction() { // Added 
     try { 
      final Class<?> notificationBuilderClass = Class.forName("android.app.Notification$Builder"); 
      notificationBuilderClass.getDeclaredMethod("setProgress", new Class[] {Integer.TYPE, Integer.TYPE, Boolean.TYPE}); 
      this.hasSetProgressFunction = true; 
     } catch (final Exception e) { 
      this.hasSetProgressFunction = false; 
     } 
     this.hasCheckedForSetProgressFunction = true; 
    } 
// ... 
    @Override 
    public Notification updateNotification(Context c) { 
     if(!this.hasCheckedForSetProgressFunction) { // Added 
      this.CheckForFunction(); // Added 
     } // Added 
    // ... 
      builder.setContentTitle(mTitle); 
      if(this.hasSetProgressFunction) { // Added 
       if (mTotalKB > 0 && -1 != mCurrentKB) { 
        builder.setProgress((int)(mTotalKB>>8), (int)(mCurrentKB>>8), false); 
       } else { 
        builder.setProgress(0,0,true); 
       } 
      } // Added 
    // ... 
    } 
} 

Это ответ от "Android разработчика" используется по-другому;)

1

@Fuglsang и @android разработчика ответ работает для меня, это прекрасно ...

static public DownloadNotification.ICustomNotification createCustomNotification() 
{ 
    try 
    { 
    final Class<?> notificationBuilderClass = Class.forName("android.app.Notification$Builder"); 
    notificationBuilderClass.getDeclaredMethod("setProgress", new Class[] {Integer.TYPE, Integer.TYPE, Boolean.TYPE}); 
    return new V11CustomNotification(); 
    } 
    catch (final Exception e) 
    { 
    return new V3CustomNotification(); 
    } 
} 
0

Немного меньше усилий будет загрузить библиотеку NotificationCompat2 JAR и указывают, что вместо этого.

2

У меня была проблема с уведомлениями на планшете (Galaxy Tab с Android 3). Утилита NotificationCompat с версией версии android-support-v4.jar 10 выдает эту ошибку. Вероятно, это ошибка в библиотеке поддержки.

java.lang.NoSuchMethodError: android.app.Notification$Builder.setProgress 
at android.support.v4.app.NotificationCompatIceCreamSandwich.add(NotificationCompatIceCreamSandwich.java:31) 
at android.support.v4.app.NotificationCompat$NotificationCompatImplIceCreamSandwich.build(NotificationCompat.java:104) 
at android.support.v4.app.NotificationCompat$Builder.build(NotificationCompat.java:558) 

Я решил эту проблему, используя эту отремонтированную библиотеку поддержки rev. 10: http://code.google.com/p/yuku-android-util/source/browse/ActionBarSherlock4/libs/android-support-v4.jar. С этим JAR он отлично работает для меня.

Благодаря yukuku: http://code.google.com/p/android/issues/detail?id=36359

EDIT: Новый Support Library, revision 11 (November 2012) исправить эту проблему.

Смежные вопросы