且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android的活动涉及到前台经理报警后,

更新时间:2023-01-04 19:28:20

您应该做的这一切在的 BroadcastReceiver的。没有用户界面,并有一个上下文变量传递到接收器的的onReceive()方法,它可以让你基本上做什么活动呢,不需要实际的用户界面。这意味着,你可以设置铃声,显示状态栏通知等。 你的BroadcastReceiver类应该是这个样子:

You should do all of this in a BroadCastReceiver. There is no UI, and there is a Context variable passed on to the Receiver's onReceive() method which allows you to basically do anything the Activity does, without having an actual UI. This means that you can set the ringer, show the status bar notification, etc. Your BroadcastReceiver class should look something like:

public class AlarmBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
    //Change ringer mode
    //Add notification in status bar
    //Other boring stuff here...
    Toast.makeText(context,"Finishing",2000).show();
    }
}

请注意,对于你的吐司,命名变量上下文被使用。

Note that for your Toast, the variable named context is used.

和您的 AlarmManager code应该是这个样子:

And your AlarmManager code should look something like this:

Intent intent = new Intent(this, AlarmBroadcastReceiver.class);
pendingIntent = PendingIntent.getBroadcast(this,req_code, intent, PendingIntent.FLAG_CANCEL_CURRENT);    
AlarmManager am = (AlarmManager)getSystemService(Activity.ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),AlarmManager.INTERVAL_DAY*7,
                    pendingIntent);

您的清单应该有这样的:

Your manifest should have this:

 <receiver android:name=".AlarmBroadcastReceiver" >
        </receiver>