我正在为Android手机和平板电脑制作字典。我已经在我的开发者帐户上提交了该文件,我的工作就像手机上的魅力一样。当我试图在我的三星Galaxy选项卡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 :(得分: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();
}
}
答案 1 :(得分: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开发者”以不同方式使用的答案;)
答案 2 :(得分:2)
我在平板电脑上遇到通知问题(Galaxy Tab with Android 3)。带有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
编辑:新Support Library, revision 11 (November 2012)解决了这个问题。
答案 3 :(得分: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
答案 4 :(得分: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();
}
}
答案 5 :(得分:0)
我在Toshiba Thrive上看到同样的失败。 “android开发者”的答案有效。基本上这意味着download_library未在V11设备上进行测试。
答案 6 :(得分:0)
稍微减少下载NotificationCompat2 JAR库并指向它的工作量。