Вы можете использовать AlertDialog
с transparent activity
. как показано ниже:
class AlertDialogActivity : AppCompactActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
showAlertMessage(getString(R.string.app_name),"Alert message")
startAlarmSound()
}
private fun startAlarmSound() {
val alarmSound: Uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM)
mp = MediaPlayer.create(this, alarmSound)
mp.start()
}
// here using alertdialog you can use
private fun showAlertMessage(titile: String, msg: String) {
AlertDialog.Builder(this)
.setTitle(title)
.setMessage(msg)
.setPositiveButton("Cancel") { dialog, which ->
if (mp.isPlaying) mp.stop()
dialog.dismiss()
finish()
}.setNegativeButton("Edit"){dialog, which ->
// handle edit options clicked here
}.setNeutralButton("Snooze"){dialog, which ->
// handle Snooze options clicked here
}.show()
}
}
Для активности transparent
вы должны настроить свою activity
тему следующим образом
<style name="TransparentTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
А внутри вашего файла manifest
используйте custom theme
для AlertDialogActivity
:
<activity android:name="AlertDialogActivity"
android:theme="@style/TransparentTheme"/>
А с вашего BroadcastReceiver
позвоните своему AlertDialogActivity
, как показано ниже:
public void onReceive(Context context, Intent intent){
// ....
showAlert(context);
}
private void showAlert(Context context) {
Intent intent = new Intent(context, AlertDialogActivity.class);
intent .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent );
}