我希望有一个BroadcastReciver在应用程序启动时调用!(例如当用户打开电报应用程序时我的BroadcastResiver调用) 我有这个课程,呼叫每个'call_period' millseconds:
public class StartupReceiver extends BroadcastReceiver {
static final String TAG = "SR";
final int startupID = 1111111;
private static int call_period=5000;
Database db;
@Override
public void onReceive(Context context, Intent intent) {
db=new Database(context);
db.open();
call_period=db.getChechTime();
db.close();
final AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
try{
Intent i7 = new Intent(context, CheckRunningApplicationReceiver.class);
PendingIntent ServiceManagementIntent = PendingIntent.getBroadcast(context,startupID, i7, 0);
alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME,SystemClock.elapsedRealtime(), call_period, ServiceManagementIntent);
} catch (Exception e) {
Log.i(TAG, "Exception : "+e);
}
}
public void setCallPeriod(int millsec){
call_period=millsec;
}
}
如何在应用程序启动时更改它以进行调用?