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
WifiManager wifiMan = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); | |
WifiInfo wifiInf = wifiMan.getConnectionInfo(); | |
int ipAddress = wifiInf.getIpAddress(); | |
String ip = String.format("%d.%d.%d.%d", (ipAddress & 0xff),(ipAddress >> 8 & 0xff),(ipAddress >> 16 & 0xff),(ipAddress >> 24 & 0xff)); |
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
public void AttenuateAudio(float[] data, int decibels) | |
{ | |
float gain = (float)Math.Pow(10, (double)-decibels / 20.0); | |
for (int i = 0; i < data.Length; i++) | |
{ | |
data[i] *= gain; | |
} | |
} |
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
//Map to JSON: | |
Map map = new HashMap(); | |
map.put("name", "foo"); | |
map.put("nickname", "bar"); | |
String jsonText = JSONValue.toJSONString(map); | |
//JSON to List/Map: | |
String s = yourJsonString; | |
List list = (JSONArray) JSONValue.parse(s); |
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
// Sending side | |
byte[] data = text.getBytes("UTF-8"); | |
String base64 = Base64.encodeToString(data, Base64.DEFAULT); | |
// Receiving side | |
byte[] data = Base64.decode(base64, Base64.DEFAULT); | |
String text = new String(data, "UTF-8"); |
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
//While loop you are running is running on a default Thread termed as the ui thread so in short | |
//run while loops on separate threads.. eg.. | |
new Thread(new Runnable() { | |
@Override | |
public void run() { | |
// Your hard while loop here | |
//get whatever you want and update your ui with ui communication methods. | |
} | |
).start(); |
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
//Add the following override to your activity, | |
//This ought to fix the color banding issue you are seeing | |
//by setting the window format to support more colors. | |
@Override | |
public void onAttachedToWindow() { | |
getWindow().setFormat(PixelFormat.RGBA_8888); | |
} | |
//More info : http://developer.android.com/reference/android/view/Window.html#setFormat(int) |
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
// From android 4.1 / 4.2, the following Roboto font families are available: | |
android:fontFamily="sans-serif" // roboto regular | |
android:fontFamily="sans-serif-light" // roboto light | |
android:fontFamily="sans-serif-condensed" // roboto condensed | |
android:fontFamily="sans-serif-thin" // roboto thin (android 4.2) | |
android:fontFamily="sans-serif-medium" // roboto medium (android 5.0) | |
// in combination with this | |
android:textStyle="normal|bold|italic" |
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
/** | |
* Ensures that the caller receives an usable multicast socket. | |
* In case the network configuration does not have a default gateway | |
* set, the multicast socket might not work. This is the case when | |
* the device is connected to a Wireless Direct printer. In that | |
* cases, force a network interface into the socket. | |
* | |
* @return A ready-to-use multicast socket. | |
*/ | |
public static MulticastSocket createMulticastSocket(Context context) |
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
//Simple helper class to encrypt and decrypt strings using AES128. | |
//The result is Ascii-encoded (actually hex, no base64), so no byte[] has to be stored. | |
//A SEED value is used as a shared secret (“Master-Password”). | |
//Only with the same SEED the stored values can be decrypted. | |
package net.sf.andhsli.hotspotlogin; | |
import java.security.SecureRandom; | |
import javax.crypto.Cipher; | |
import javax.crypto.KeyGenerator; | |
import javax.crypto.SecretKey; |
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
WifiConfiguration wifiConfig = new WifiConfiguration(); | |
wifiConfig.SSID = String.format("\"%s\"", ssid); | |
wifiConfig.preSharedKey = String.format("\"%s\"", key); | |
WifiManager wifiManager = (WifiManager)getSystemService(WIFI_SERVICE); | |
//remember id | |
int netId = wifiManager.addNetwork(wifiConfig); | |
wifiManager.disconnect(); | |
wifiManager.enableNetwork(netId, true); | |
wifiManager.reconnect(); |
OlderNewer