У меня есть задачи Asyn c в модуле библиотеки, которые вызываются из модуля приложения.
Когда я помещаю создание и создание уведомлений в модуль библиотеки, я не могу установить обратный вызов Intent
(или PendingIntent
) через NotificationCompat.Builder().setContentIntent
, поскольку классы приложения не разрешены:
// build notification - https://developer.android.com/training/notify-user/navigation#define_your_apps_activity_hierarchy
// Create an Intent for the activity and inflate the back stack
Intent resultIntent = new Intent(this, ImportExportActivity.class); // <-- second argument is unresolved
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addNextIntentWithParentStack(resultIntent);
PendingIntent pendingIntent =
stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
new NotificationCompat.Builder(mActivity, Constants.CHANNEL_ID_TRANSFER_PROGRESS)
.setSmallIcon(R.drawable.ab_icon)
.setContentTitle(mActivity.getString(R.string.import_export_notification_title_import))
.setContentText(mActivity.getString(R.string.import_export_notification_title_text))
//.setStyle(new NotificationCompat.BigTextStyle().bigText(R.string.notification_title_longer_text))
.setContentIntent(pendingIntent) <-- can't do that without circular dependency
.setAutoCancel(true)
.setOnlyAlertOnce(true)
.setTimeoutAfter(10000)
.setPriority(NotificationCompat.PRIORITY_LOW)
.setCategory(NotificationCompat.CATEGORY_SERVICE)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
Если я создаю уведомление в модуле приложения, AsyncTask модуля библиотеки не запускает уведомление.