// String BROADCAST_ACTION = "com.example.uniqueTag"; public void sendNotification () { NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); Intent intent = new Intent(BROADCAST_ACTION); // Intent .getBroadcast PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intentStopTrip, 0); // Notification BuilderNote = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_example) .setContentTitle("Example title") .setContentText("Example text") .setContentIntent(pendingIntentPush) // pendingIntent .addAction(R.mipmap.ic_example, "Button name", pendingIntent) .build(); // BuilderNote.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, BuilderNote); }
public class ExampleReciver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { exampleMethod(); } }
<receiver android:name=".StopTimerReciver" android:enabled="true" android:exported="true"> <intent-filter> <action android:name="com.example.uniqueTag" /> </intent-filter> </receiver>
Source: https://habr.com/ru/post/354758/
All Articles