0

我正在为安卓手机和平板电脑制作字典。我已经在我的开发者帐户上提交了文件,我在手机上的工作就像一个魅力。当我尝试在我的三星 Galaxy Tab 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

我不知道为什么我不会下载。在该屏幕出现之前,它会显示文件的大小,我知道我可以设置它。

请帮助我,谢谢

4

7 回答 7

3

我也有同样的问题 。不过,我有线索:

如果您搜索“setProgress”,您可以看到它存在于文件“V11CustomNotification”中,该文件旨在(我认为)用于 API11+,其中包括用于平板电脑的蜂窝。

"setProgress" 仅适用于 API14+ ,因此您会遇到异常。

现在,问题是,如何解决它...

有两种方法: 1.检查“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();
  }
}
于 2012-03-26T14:08:05.630 回答
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开发人员”的答案;)

于 2012-05-08T10:34:02.500 回答
2

我在平板电脑(带有 Android 3 的 Galaxy Tab)上的通知有问题。带有 android-support-v4.jar 修订版 10 的 NotificationCompat 实用程序会引发此错误。这可能是支持库中的错误。

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

编辑:新的支持库,修订版 11(2012 年 11 月)解决了这个问题。

于 2012-10-11T13:22:30.777 回答
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

于 2012-04-11T13:36:51.820 回答
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();
  }
}
于 2012-05-14T08:24:07.030 回答
0

我在东芝 Thrive 上看到了同样的失败。“android developer”的答案有效。基本上这意味着 download_library 没有在 V11 设备上进行测试。

于 2012-04-06T05:12:40.777 回答
0

下载 NotificationCompat2 JAR 库并指向它的工作量会稍微少一些。

于 2012-09-26T08:29:48.517 回答