Если вам нужна похожая функциональность, например, AlertDialog, вы также можете добиться этого с помощью Dialog Acitvity.Я написал небольшой код, который может продемонстрировать, что именно вы хотите в своем вопросе.Я приложил ссылки на github и gif video, которые визуализируют то, что я делал в коде.
Github: https://github.com/shahzadafridi/NotificationOpenDialogActivity
Демонстрационный Gif: https://i.imgur.com/cVW6IyS.gifv
MainActivity.java
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void sendNotification(View view){
sendMeNotification("Hell this is notification.");
}
public void sendMeNotification(String message) {
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
NotificationCompat.Builder notification = null;
Intent main = new Intent(this, AboutActivity.class);
main.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 001, main, PendingIntent.FLAG_ONE_SHOT);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
int importance = NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel channel = new NotificationChannel(this.getString(R.string.channel_id), this.getString(R.string.channel_name), importance);
channel.setDescription("It's a personal channel");
channel.enableVibration(false);
channel.enableLights(true);
channel.setLightColor(Color.RED);
manager.createNotificationChannel(channel);
notification = new NotificationCompat.Builder(this, channel.getId());
} else {
notification = new NotificationCompat.Builder(this, this.getString(R.string.channel_id));
}
Uri sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
notification.setDefaults(Notification.DEFAULT_ALL)
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.mipmap.ic_launcher)
.setPriority(Notification.PRIORITY_HIGH)
.setContentTitle(this.getString(R.string.app_name))
.setContentText(message)
.setStyle(new NotificationCompat.BigTextStyle().bigText(message))
.setAutoCancel(true)
.setSound(sound)
.setLights(Color.RED, 200, 200)
.setContentIntent(pendingIntent);
manager.notify(0, notification.build());
}
}
AboutActivity.java
public class AboutActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);
}
}
AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".AboutActivity" android:theme="@style/NoTitleDialog"></activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
В теге AboutActivity задайте тему, которую мы определили в styles.xml
Styles.xml
<style name="NoTitleDialog" parent="@style/Theme.AppCompat.Dialog">
<item name="windowNoTitle">true</item>
</style>
Добавьте этот стиль для выполнения действия в виде диалогового действия.