The problem is that the BroadcastReceiver does not react in any way to the custom action that I send, but it works fine with the system actions. Who knows what could be the problem? Thanks in advance for the answer!

Manifesto

<application android:allowBackup="true" android:icon="@mipmap/icon" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".auth.LoginActivity" android:theme="@style/AppTheme.NoActionBar"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".mainactivity.MainActivity" android:theme="@style/AppTheme.NoActionBar" /> <activity android:name=".addtaskactivity.AddTaskActivity" /> <activity android:name=".settingsactivity.SettingsActivity" android:theme="@style/AppTheme" /> <receiver android:name="packagename.ExecuteTaskReceiver" android:exported="false" android:enabled="true"> <intent-filter> <action android:name="packagename.TASK_DONE"/> </intent-filter> </receiver> </application> 

Receiver

 public class ExecuteTaskReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Toast.makeText(context,"SSSSSSS",Toast.LENGTH_LONG).show(); NotificationManager mNotifyMgr = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setContentTitle(intent.getStringExtra(AppKeys.TASK_TITLE)) .setOngoing(false) .setPriority(NotificationCompat.PRIORITY_DEFAULT) .setAutoCancel(true); Intent i = new Intent(context, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity( context, 0, i, PendingIntent.FLAG_ONE_SHOT ); Uri uri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); mBuilder.setSound(uri); mBuilder.setContentIntent(pendingIntent); mNotifyMgr.notify(12345, mBuilder.build()); } } 

Alarmmanager

 Context context = mTaskView.getContext(); AlarmManager am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(); intent.setAction(AppKeys.TASK_DONE); //intent.setClass(context, ExecuteTaskReceiver.class); intent.putExtra(AppKeys.TASK_TITLE, mTask.getTitle()); mTaskView.getContext().sendBroadcast(intent); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_ONE_SHOT); am.set(AlarmManager.RTC_WAKEUP, getTaskTime().getTimeInMillis(), pendingIntent); 
  • Android version? Through LocalBroadcastManager tried? - Eugene Krivenja
  • Android version 7.0, 7.1.1. LocalBroadcastManager did not try - Serhiy

1 answer 1

In the case of Android 8+, you need to specify the exact recipient in the intent:

 Intent intent = new Intent(context, ExecuteTaskReceiver.class); intent.setAction(AppKeys.TASK_DONE); 

Or to regat the receiver in rantayme.
https://developer.android.com/about/versions/oreo/background.html#broadcasts

  • Probyval from the very beginning! Did not help - Serhiy