SSH connection with Java

Use JSch import com.jcraft.jsch.*; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Scanner; /** * @author World */ public class SSHReadFile { public static void main(String args[]) { String user = “john”; String password = “mypassword”; String host = “192.168.100.23”; int port = 22; String remoteFile = “/home/john/test.txt”; try { JSch jsch = new JSch(); Session session = … Read more

When to close db connection on android? Every time after your operation finished or after your app exit

I don’t know of any performance penalties in frequent closing/opening of the database (regardless of its size). I think the answer to this question also depends on what type of application is accessing the database. Do you “re-query” the database a lot? Then it seems rectified to keep it open. Do you fetch different data … Read more

Check for Internet connection using the iOS SDK [duplicate]

Best way is to use Reachability code. Check here for apple sample code. That has a lot of convenience methods to check internet availability, Wifi/WAN connectivity check etc.. For eg:- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkChanged:) name:kReachabilityChangedNotification object:nil]; reachability = [Reachability reachabilityForInternetConnection]; [reachability startNotifier]; – (void)networkChanged:(NSNotification *)notification { NetworkStatus remoteHostStatus = [reachability currentReachabilityStatus]; if(remoteHostStatus == NotReachable) { … Read more

Get signal strength of WIFI and Mobile Data

Wifi: WifiManager wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE); int linkSpeed = wifiManager.getConnectionInfo().getRssi(); In case of mobile it should work: TelephonyManager telephonyManager = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE); CellInfoGsm cellinfogsm = (CellInfoGsm)telephonyManager.getAllCellInfo().get(0); CellSignalStrengthGsm cellSignalStrengthGsm = cellinfogsm.getCellSignalStrength(); cellSignalStrengthGsm.getDbm(); Then You should compare this signal levels and if WIFI signal is better keep it turn on, but if mobile is better disconnect wifi