aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/fil/libre/repwifiapp/RepWifiIntentReceiver.java
blob: 3f507ec040f158c1487b51b110ce09b384bf2b97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package fil.libre.repwifiapp;

import fil.libre.repwifiapp.ActivityLauncher.RequestCode;
import fil.libre.repwifiapp.activities.MainActivity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;

public class RepWifiIntentReceiver extends BroadcastReceiver {

    public void onReceive(Context context, Intent intent) {

        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context
                        .getApplicationContext());
        if (!prefs.getBoolean("enable_autostart", false)) {
            Log.d("RepWifi", "autostart is false");
            return;
        }

        Log.d("RepWifi", "Autostart is true");
        String a = intent.getAction();

        if (a.equals(Intent.ACTION_BOOT_COMPLETED) || a.equals(Intent.ACTION_REBOOT)) {
            launchRepWifiMainActivity(context, RequestCode.NONE);
        }

    }

    private void launchRepWifiMainActivity(Context context, int reqCode) {

        Intent intent = new Intent(context, MainActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        if (reqCode >= 0) {
            intent.putExtra(ActivityLauncher.EXTRA_REQCODE, reqCode);
        }
        context.startActivity(intent);

    }
}