1

I want to have a BroadcastReceiver that called when an application is launched! (for example when user open telegram application my BroadcastResiver called) I have this class that called every 'call_period' milliseconds:

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;
    }
}

how can I change it to call when an application is launched?

Cœur
  • 37,241
  • 25
  • 195
  • 267

0 Answers0