0

私はAndroid携帯電話とタブレット用の辞書を作っています。私は自分の開発者アカウントでファイルをコミットしました、そして私は電話で魅力のように働きます。サムスンギャラクシータブ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+ でのみ使用できるため、例外が発生します。

さて、問題は、それを修正する方法です...

2 つの方法があります。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

NotificationCompat2 JARライブラリをダウンロードして、代わりにそれを指すのは、少し手間がかかりません。

于 2012-09-26T08:29:48.517 に答える
0

東芝スライブでも同じ失敗が見られます。「アンドロイド開発者」からの答えはうまくいきます。基本的に、これは download_library が V11 デバイスでテストされていないことを意味します。

于 2012-04-06T05:12:40.777 に答える