-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Android] Replace start on boot option with Smart Connect
- Loading branch information
1 parent
860a73e
commit 0815fe2
Showing
11 changed files
with
117 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 0 additions & 19 deletions
19
android/app/src/main/java/com/texasgamer/zephyr/BootReceiver.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
android/app/src/main/java/com/texasgamer/zephyr/receiver/BootReceiver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.texasgamer.zephyr.receiver; | ||
|
||
import android.content.BroadcastReceiver; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.preference.PreferenceManager; | ||
|
||
import com.texasgamer.zephyr.R; | ||
import com.texasgamer.zephyr.service.NotificationService; | ||
import com.texasgamer.zephyr.service.SocketService; | ||
|
||
public class BootReceiver extends BroadcastReceiver { | ||
|
||
@Override | ||
public void onReceive(Context context, Intent intent) { | ||
Intent socketService = new Intent(context, SocketService.class); | ||
context.startService(socketService); | ||
|
||
Intent notificationService = new Intent(context, NotificationService.class); | ||
context.startService(notificationService); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
android/app/src/main/java/com/texasgamer/zephyr/receiver/WiFiReceiver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.texasgamer.zephyr.receiver; | ||
|
||
import android.content.BroadcastReceiver; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.net.NetworkInfo; | ||
import android.net.wifi.WifiManager; | ||
import android.preference.PreferenceManager; | ||
import android.util.Log; | ||
|
||
import com.texasgamer.zephyr.R; | ||
import com.texasgamer.zephyr.service.NotificationService; | ||
|
||
public class WiFiReceiver extends BroadcastReceiver { | ||
|
||
private final String TAG = this.getClass().getSimpleName(); | ||
|
||
@Override | ||
public void onReceive(Context context, Intent intent) { | ||
if (!PreferenceManager.getDefaultSharedPreferences(context).getBoolean(context.getString(R.string.pref_smart_connect), true)) { | ||
Log.i(TAG, "Smart connect is disabled, so ignoring network state change."); | ||
} | ||
|
||
if (intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)){ | ||
NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO); | ||
if (info.isConnected()) { | ||
String address = PreferenceManager.getDefaultSharedPreferences(context).getString(context.getString(R.string.pref_last_addr), ""); | ||
|
||
if (address.trim().isEmpty()) { | ||
Log.i(TAG, "No previously known address, not attempting to connect!"); | ||
} | ||
|
||
Log.i(TAG, "Connected to WiFi, attempting to connect to the server..."); | ||
Intent i = new Intent("com.texasgamer.zephyr.SOCKET_SERVICE"); | ||
i.putExtra("type", "connect"); | ||
i.putExtra("address", address); | ||
context.sendBroadcast(i); | ||
} else { | ||
Log.i(TAG, "No longer connected to WiFi, attempting to disconnect from the server..."); | ||
Intent i = new Intent("com.texasgamer.zephyr.SOCKET_SERVICE"); | ||
i.putExtra("type", "disconnect"); | ||
context.sendBroadcast(i); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
android/app/src/main/java/com/texasgamer/zephyr/util/NetworkUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.texasgamer.zephyr.util; | ||
|
||
import android.content.Context; | ||
import android.net.wifi.WifiInfo; | ||
import android.net.wifi.WifiManager; | ||
|
||
public class NetworkUtils { | ||
|
||
public static boolean isConnectedToWiFi(Context context) { | ||
WifiManager wifiMgr = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); | ||
|
||
if (wifiMgr.isWifiEnabled()) { // WiFi adapter is on | ||
WifiInfo wifiInfo = wifiMgr.getConnectionInfo(); | ||
if (wifiInfo.getNetworkId() == -1) { | ||
return false; // Not connected to an access point | ||
} | ||
return true; // Connected to an access point | ||
} else { | ||
return false; // WiFi adapter is OFF | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters