如何开始在Android立即报警

编程入门 行业动态 更新时间:2024-10-10 09:25:06
本文介绍了如何开始在Android立即报警的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图写一个code有事时激活报警。我想过使用默认的报警及消防它,当我考虑,但首先我不知道如何来触发报警或处理。第二:我不知道是否有火灾立即报警,听起来并告诉用户一个消息的最简单的方法

I'm trying to write a code that activates an alarm when something happens. I've thought on using the default alarm and fire it when I consider it, but first: I don't know how to fire the alarm or handle it. Second: I don't know if there is an easiest way to fire an immediate alarm that sounds and tells the user a message.

例如:

(真)   火灾声音报警,提示信息提醒用户其他   其他一些code

if (true) Fire an audible alarm with a message to advise the user else Some other code

感谢您的帮助。

推荐答案

AlarmManager:

AlarmManager:

public void startAlert() { Intent intent = new Intent(this, MyBroadcastReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast( this.getApplicationContext(), 234324243, intent, 0); AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (i * 1000), pendingIntent); Toast.makeText(this, "Alarm set in " + i + " seconds", Toast.LENGTH_LONG).show(); }

广播接收器:

public class MyBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Toast.makeText(context, "Don't panik but your time is up!!!!.", Toast.LENGTH_LONG).show(); // Vibrate the mobile phone Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(2000); } }

更多推荐

如何开始在Android立即报警

本文发布于:2023-11-27 11:01:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637799.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!