Скачать файлы расширения на планшет
Я делаю словарь для телефонов и планшетов Android. Я отправил файл на свою учетную запись разработчика, и я работаю как брелок на телефоне. Когда я пытаюсь запустить точно такой же код на моей вкладке Samsung 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
Я понятия не имею, почему я не буду загружать. До того, как появится этот экран, он показывает размер файла, так что я знаю, что могу его увидеть.
пожалуйста, помогите мне, спасибо
7 ответов
У меня та же проблема. у меня есть лидерство, хотя:
если вы ищете "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();
}
}
У меня были проблемы с уведомлениями на планшете (Galaxy Tab с Android 3). Утилита NotificationCompat с версией 10 android-support-v4.jar выдает эту ошибку. Вероятно, это ошибка в библиотеке поддержки.
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 у меня все работает нормально.
Благодаря Юкуку: http://code.google.com/p/android/issues/detail?id=36359
РЕДАКТИРОВАТЬ: Новая библиотека поддержки, редакция 11 (ноябрь 2012), исправить эту проблему.
Я просто добавил несколько строк кода в класс 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", используемый по-другому;)
Я решил проблему. Я ток этот код и скопировал вместо кода туда, где в 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
Ответ @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();
}
}
Я вижу ту же ошибку на Toshiba Thrive. Ответ от "разработчика Android" работает. По сути это означает, что download_library не был протестирован на устройстве V11.
Чуть меньше усилий было бы загрузить библиотеку JAR NotificationCompat2 и указать на нее.