Я разрабатываю приложение для Android. Я мое приложение, я пытаюсь показать уведомление о процессе пользователю. Но я хочу, чтобы уведомление открывало действие или удалялось при нажатии. Что я делаю, так это показываю уведомление, когда пользователь нажимает кнопку. В уведомлении будет написано «Перенос данных». Уведомление отправлено получателем.
Поэтому, когда пользователь нажимает кнопку, вызывается получатель. Но я не хочу, чтобы это уведомление удалялось или закрывалось, когда пользователь нажимал на него. Я тоже не хочу проявлять никакой активности. Я просто хочу закрыться, когда обработка данных закончится.
Это мой приемник, который показывает уведомление при нажатии кнопки
public class GalleryImageUploadReceiver extends BroadcastReceiver {
private Context context;
private NotificationCompat.Builder notification;
@Override
public void onReceive(Context pContext, Intent intent) {
this.context = pContext;
showProcessNotification();
doAsyncTaskInBackground()
}
public void doAsyncTaskInBackground()
{
//I want to close it here after task is finished
}
public void showProcessNotification()
{
try{
notification = new NotificationCompat.Builder(context);
notification.setAutoCancel(true);
notification.setSmallIcon(R.mipmap.ic_launcher);
notification.setWhen(System.currentTimeMillis());
notification.setTicker("Transferring data...");
notification.setContentTitle(context.getResources().getString(R.string.app_name));
notification.setContentTitle("Transferring data...");
notification.setOngoing(true);
notification.setDefaults(Notification.FLAG_ONGOING_EVENT);
Intent i = new Intent(context.getApplicationContext(), MainActivity.class);//In this line, I do not want to open any activity
i.putExtra("start", OfficeMainActivity.FRAGMENT_NOTIFICATIONS);
PendingIntent pendingIntent = PendingIntent.getActivity(context.getApplicationContext(),0,i,PendingIntent.FLAG_UPDATE_CURRENT);
notification.setContentIntent(pendingIntent);
NotificationManager nm = (NotificationManager)context.getApplicationContext().getSystemService(context.getApplicationContext().NOTIFICATION_SERVICE);
nm.notify(1,notification.build());
}
catch (Exception e)
{
}
}
public void uploadImages(Context context,Intent intent)
{
onReceive(context,intent);
}
}
Приемник вызывается в событии нажатия кнопки, как это
GalleryImageUploadReceiver receiver = new GalleryImageUploadReceiver();
receiver.uploadImages(getBaseContext(),new Intent());
Как видите, я установил для continue значение true, потому что хочу, чтобы его нельзя было закрыть. Но проблема в том, что он закрыт, потому что активность открыта.
Вот что я хочу:
- Я не хочу открывать действие при нажатии на уведомление.
- Я только хочу, чтобы он закрылся сам. Как я могу это сделать?
- Вместо этого может показать диалоговое окно с кнопками?