我在应用程序上工作,这个应用程序在通知栏上的每个周期都显示通知,所以我想在调用广播接收器时显示这个通知检查应用程序现在是否正在使用(我的意思是应用程序正在运行并且用户现在打开它)不要通知栏不显示通知,请帮帮我。
This is the set of alarm in oncreate:
Intent iAlarm=new Intent(HomePage.this, AlarmReciever.class);
AlarmMan alarm=new AlarmMan();
alarm.SetAlarm(HomePage.this,System.currentTimeMillis() , 60000, true, 7896) ;
and this is onstop and on resume:
@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_PACKAGE_ADDED);
filter.addDataScheme("package");
filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
AlarmReciever reciever1=new AlarmReciever();
this.registerReceiver(reciever1,filter);
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
try{
AlarmReciever reciever2=new AlarmReciever();
this.unregisterReceiver(reciever2);
}catch(Error e)
{
Log.v("error in resume", e.getMessage());
}
}
This the setalarm function:
public static void SetAlarm (Context c , long time , int period ,boolean repeat ,int id ){
AlarmManager al = (AlarmManager) c.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(c,AlarmReciever.class);
PendingIntent pi = PendingIntent.getBroadcast(c,7896,i,PendingIntent.FLAG_UPDATE_CURRENT);
if(repeat ){
al.setRepeating(AlarmManager.RTC_WAKEUP,time,period,pi);
}else {
al.set(AlarmManager.RTC_WAKEUP, time, pi);
}
}