0

I am making an dictionary for android phones and tablets. I have committed the file on my developer account, and i works like a charm on phone. When i am trying to run the exactly same code on my samsung galaxy tab 10.1, it is stuck.

        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();
        }

    }

It comes with this exception :

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

I have no idea why i wont download. Before that screen comes, it shows the size of the file så i know that i can se it.

please help me, thanks

Fuglsang
  • 19
  • 1
  • 3
  • When you say "it is stuck", where does it get to in debug? Is there an obvious point of failure? – HaemEternal Mar 21 '12 at 14:57
  • it goes all the way through, but it never starts downloading. It just keep showing the screen with "starting". When i then press the notification, it just starts over again. – Fuglsang Mar 21 '12 at 15:05
  • FYI If you had ran `Lint` over your project it would have picked this up. – Blundell Apr 18 '12 at 15:30
  • Thanks for the code, I've reported this issue to Google and referenced this page: http://code.google.com/p/android/issues/detail?id=30755&can=4&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars Hopefully it gets fixed soon! – Andy May 11 '12 at 07:18

7 Answers7

3

i have the same problem . i have a lead , though:

if you search for "setProgress" , you can see that it exists on the file "V11CustomNotification" , which is intended (i think ) for API11+ , which includes honeycomb for the tablets.

"setProgress" is only available for API14+ , so you get an exception.

now , the question is , how to fix it ...

there are 2 ways: 1.check if the method exists on "CustomNotificationFactory" , and if not , return the V3CustomNotification instance.

2.change the code that calls the "setProgress" method , so that it will work for API11..13 (including).

in any case , please tell us what you've done (exactly) , so that we could all benefit from it.

i've chosen fix #1 , since it's easier and i didn't succeed with #2 (i tried) : edit the file , and use there the next code:

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();
  }
}
android developer
  • 114,585
  • 152
  • 739
  • 1,270
2

I simply added a few lines of code to the com.google.android.vending.expansion.downloader.impl .V11CustomNotification class:

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

It's the answer from "android developer" used in a different way ;)

nhaar
  • 21
  • 4
2

I had problem with notifications on tablet (Galaxy Tab with Android 3). NotificationCompat utility with android-support-v4.jar revision 10 throws this error. It is probably bug in support library.

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)

I solved this problem using this repaired support library rev. 10: http://code.google.com/p/yuku-android-util/source/browse/ActionBarSherlock4/libs/android-support-v4.jar. With this JAR, it works fine for me.

Thanks to yukuku: http://code.google.com/p/android/issues/detail?id=36359

EDIT: New Support Library, revision 11 (November 2012) fix this problem.

petrnohejl
  • 7,581
  • 3
  • 51
  • 63
1

I have solved the problem. I tok this code and copied instead of the code there where in 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();
  }
}

I works perfect :D thanks a lot :D

Fuglsang
  • 19
  • 1
  • 3
1

@Fuglsang and @android developer's answer works for me, it's perfect...

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();
  }
}
Jackoe
  • 11
  • 1
0

I see the same failure on a Toshiba Thrive. The answer from "android developer" works. Basically this means that the download_library was not tested on a V11 device.

Marc
  • 21
  • 1
0

Slightly less effort would be to download the NotificationCompat2 JAR library and point to that instead.

albnok
  • 521
  • 2
  • 14