List of usage examples for android.text.format Formatter formatIpAddress
@Deprecated public static String formatIpAddress(int ipv4Address)
From source file:Main.java
/** get IP of the gateway this device is connected to (useful if gateway has server running) */ public static String getHostIpAddress(Context mContext) { WifiManager wifi = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); String ip = Formatter.formatIpAddress(wifi.getDhcpInfo().gateway); return ip;/*from w w w.ja v a 2s . co m*/ }
From source file:mf.sync.utils.SessionInfo.java
@SuppressWarnings("deprecation") public static InetAddress getWifiAddress(Context c) { if (c == null) throw new RuntimeException("Context is null"); WifiManager wm = (WifiManager) c.getSystemService(Context.WIFI_SERVICE); try {//from w w w. j a va2 s. c o m return InetAddress.getByName(Formatter.formatIpAddress(wm.getConnectionInfo().getIpAddress())); } catch (UnknownHostException e) { Log.e("sync utils", "cannot get wifi address, returning null..."); } return null; }
From source file:com.example.gemswin.screancasttest.MainActivity_Reciever.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_reciever); WifiManager wm = (WifiManager) getSystemService(WIFI_SERVICE); String ip = Formatter.formatIpAddress(wm.getConnectionInfo().getIpAddress()); TextView text = (TextView) findViewById(R.id.textView); planetList = new ArrayList<String>(); mTextureView = (TextureView) findViewById(R.id.textureView); mTextureView.setSurfaceTextureListener(this); mTextureView.requestLayout();//from ww w .j ava 2 s . c o m mTextureView.invalidate(); mTextureView.setOpaque(false); pref = new PrefManager(getApplicationContext()); text.setText(ip); mTask = new ReceiverAsyncTask(getApplicationContext(), this); mTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }
From source file:at.tugraz.ist.akm.networkInterface.WifiIpAddress.java
@SuppressWarnings("deprecation") private String readWifiIP4Address() { String ip4Address = "0.0.0.0"; byte[] ipAddress = BigInteger.valueOf(mWifiManager.getConnectionInfo().getIpAddress()).toByteArray(); try {// www .j a v a 2 s . c om InetAddress address = InetAddress.getByAddress(ipAddress); String concreteAddressString = address.getHostAddress().toUpperCase(Locale.getDefault()); if (InetAddressUtils.isIPv4Address(concreteAddressString)) { ip4Address = Formatter.formatIpAddress(mWifiManager.getConnectionInfo().getIpAddress()); } } catch (UnknownHostException e) { return ip4Address; } return ip4Address; }
From source file:com.example.gemswin.screencastrecevertest.MainActivity_Reciever.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_reciever); WifiManager wm = (WifiManager) getSystemService(WIFI_SERVICE); String ip = Formatter.formatIpAddress(wm.getConnectionInfo().getIpAddress()); TextView text = (TextView) findViewById(R.id.textView); planetList = new ArrayList<String>(); mTextureView = (TextureView)findViewById(R.id.textureView); mTextureView.setSurfaceTextureListener(this); mTextureView.requestLayout();/*from w ww.j a v a 2s. com*/ mTextureView.invalidate(); mTextureView.setOpaque(false); logout = (Button) findViewById(R.id.logout); cast = (Button) findViewById(R.id.castAsmaster); doubtbutton = (Button) findViewById(R.id.doubt); viewbutton = (Button) findViewById(R.id.viewdoubt); pref = new PrefManager(getApplicationContext()); text.setText(ip); logout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { pref.logout(); Intent i = new Intent(MainActivity_Reciever.this, LoginActivity.class); startActivity(i); finish(); } }); cast.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new allowcast().execute(); } }); viewbutton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //pref.logout(); // LOOK HERE ASH /*Intent i = new Intent(MainActivity_Reciever.this,DoubtActivity.class); startActivity(i);*/ new viewdoubttask().execute(); } }); doubtbutton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //pref.logout(); // LOOK HERE ASH /*Intent i = new Intent(MainActivity_Reciever.this,DoubtActivity.class); startActivity(i);*/ DoubtBox(); } }); mTask = new ReceiverAsyncTask(this); mTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); Intent intent1 = new Intent(this, MyBroadcastReceiver.class); intent1.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getBroadcast( getApplicationContext(), 234324243, intent1, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager alarmManager = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE); alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (10 * 1000), pendingIntent); }
From source file:com.iiitd.networking.UDPMessenger.java
/** * Sends a broadcast message (TAG EPOCH_TIME message). Opens a new socket in case it's closed. * @param message the message to send (multicast). It can't be null or 0-characters long. * @return//ww w . jav a 2s . co m * @throws IllegalArgumentException */ public boolean sendMessage(String message) throws IllegalArgumentException { if (message == null || message.length() == 0) throw new IllegalArgumentException(); // Check for WiFi connectivity ConnectivityManager connManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (mWifi == null || !mWifi.isConnected()) { Log.d(DEBUG_TAG, "Sorry! You need to be in a WiFi network in order to send UDP multicast packets. Aborting."); return false; } // Check for IP address WifiManager wim = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); int ip = wim.getConnectionInfo().getIpAddress(); // Create the send socket if (socket == null) { try { socket = new DatagramSocket(); } catch (SocketException e) { Log.d(DEBUG_TAG, "There was a problem creating the sending socket. Aborting."); e.printStackTrace(); return false; } } // Build the packet DatagramPacket packet; Message msg = new Message(TAG, message); byte data[] = msg.toString().getBytes(); WifiInfo wifiInfo = wim.getConnectionInfo(); int ipa = wifiInfo.getIpAddress(); String ipAddress = Formatter.formatIpAddress(ipa); try { // packet = new DatagramPacket(data, data.length, InetAddress.getByName(ipToString(ip, true)), MULTICAST_PORT); packet = new DatagramPacket(data, data.length, InetAddress.getByName(ipAddress), MULTICAST_PORT); } catch (UnknownHostException e) { Log.d(DEBUG_TAG, "It seems that " + ipToString(ip, true) + " is not a valid ip! Aborting."); e.printStackTrace(); return false; } try { socket.send(packet); } catch (IOException e) { Log.d(DEBUG_TAG, "There was an error sending the UDP packet. Aborted."); e.printStackTrace(); return false; } return true; }
From source file:com.ifoer.util.NetPOSPrinter.java
public int printPic(Bitmap bmp) { WifiManager wifi_service = (WifiManager) this.mContext.getSystemService("wifi"); DhcpInfo dhcpinfo = wifi_service.getDhcpInfo(); WifiInfo wifi_info = wifi_service.getConnectionInfo(); if (wifi_info != null && wifi_info.getSSID() != null && !wifi_info.getSSID().startsWith("X-431PRINTER")) { return PRINT_NOT_CONNECT; }/*from ww w .j ava 2 s .c om*/ this.serverAddress = dhcpinfo.serverAddress; try { this.wifiSocket = new Socket(Formatter.formatIpAddress(this.serverAddress), PRINT_PORT); this.dos = new DataOutputStream(this.wifiSocket.getOutputStream()); this.in = new DataInputStream(this.wifiSocket.getInputStream()); } catch (UnknownHostException e1) { e1.printStackTrace(); } catch (IOException e12) { e12.printStackTrace(); } if (this.dos == null || this.in == null) { return PRINT_NOT_CONNECT; } byte[] data = new byte[3]; data[0] = (byte) 27; data[ERROR_PRINT_JAM] = (byte) 51; try { this.dos.write(data, 0, data.length); data[0] = (byte) 0; data[ERROR_PRINT_JAM] = (byte) 0; data[ERROR_PRINT_WILL_NO_PAPER] = (byte) 0; } catch (IOException e122) { e122.printStackTrace(); } byte[] escj = new byte[3]; escj[0] = (byte) 27; escj[ERROR_PRINT_JAM] = (byte) 74; int i = 3; byte[] esccheck = new byte[] { (byte) 29, (byte) 114, (byte) 73 }; byte[] escBmp = new byte[5]; escBmp[0] = (byte) 27; escBmp[ERROR_PRINT_JAM] = (byte) 42; escBmp[ERROR_PRINT_WILL_NO_PAPER] = SmileConstants.TOKEN_LITERAL_NULL; escBmp[3] = (byte) (bmp.getWidth() % KEYRecord.OWNER_ZONE); escBmp[ERROR_PRINT_NO_PAPER] = (byte) (bmp.getWidth() / KEYRecord.OWNER_ZONE); for (int i2 = 0; i2 < (bmp.getHeight() / 24) + ERROR_PRINT_JAM; i2 += ERROR_PRINT_JAM) { try { this.dos.write(escBmp, 0, escBmp.length); } catch (IOException e) { e.printStackTrace(); } for (int j = 0; j < bmp.getWidth(); j += ERROR_PRINT_JAM) { for (int k = 0; k < 24; k += ERROR_PRINT_JAM) { if ((i2 * 24) + k < bmp.getHeight()) { if (Color.red(bmp.getPixel(j, (i2 * 24) + k)) == 0) { int i3 = k / ERROR_PRINT_ACTUATOR_FAULT; data[i3] = (byte) (data[i3] + ((byte) (ERROR_PRINT_HEAD_OVERHEATING >> (k % ERROR_PRINT_ACTUATOR_FAULT)))); } } } try { this.dos.write(data, 0, data.length); data[0] = (byte) 0; data[ERROR_PRINT_JAM] = (byte) 0; data[ERROR_PRINT_WILL_NO_PAPER] = (byte) 0; } catch (IOException e2) { e2.printStackTrace(); } } try { if (i2 % 10 == 0) { this.dos.write(esccheck); if (this.in.readByte() == null) { this.dos.write(escj, 0, escj.length); } } else { this.dos.write(escj, 0, escj.length); } } catch (IOException e22) { e22.printStackTrace(); } } i = 3; byte[] escf = new byte[] { (byte) 29, (byte) 122, (byte) 49 }; i = 3; byte[] esck = new byte[] { (byte) 27, (byte) 74, (byte) 64 }; try { this.dos.write(escf); this.dos.write(esck); this.result = this.in.readByte(); try { this.dos.close(); this.in.close(); } catch (IOException e222) { e222.printStackTrace(); } return this.result; } catch (IOException e3) { return PRINT_NOT_CONNECT; } }
From source file:com.doomy.padlock.MainActivity.java
/** * Gets the ip adress wireless./*ww w .jav a 2 s . c o m*/ * * @return The ip adress wireless. */ public static String getIPAdressWifi() { WifiManager mWifiManager = (WifiManager) mActivity.getSystemService(WIFI_SERVICE); WifiInfo mWifiInfo = mWifiManager.getConnectionInfo(); int mIP = mWifiInfo.getIpAddress(); String mIPAddress = Formatter.formatIpAddress(mIP); return mIPAddress; }
From source file:com.eurotong.orderhelperandroid.Common.java
@SuppressWarnings("deprecation") public static String GetIpAddress() { String id = "UNKNOWN"; Object idObject = null;//from www. ja v a 2 s . c o m WifiManager wifiMan = (WifiManager) MyApplication.getAppContext().getSystemService(Context.WIFI_SERVICE); //formatIpAddress is deprecated. because it only handles ip4 id = Formatter.formatIpAddress(wifiMan.getConnectionInfo().getIpAddress()); return id; }
From source file:com.fastbootmobile.encore.cast.CastModule.java
private String getWiFiIpAddress() { WifiManager wifiMgr = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiMgr.getConnectionInfo(); int ip = wifiInfo.getIpAddress(); return Formatter.formatIpAddress(ip); }