Geek-Info

The comprehensive feed for all Computer Science enthusiasts.

 T o test your applications in development over Wi-Fi Connect the device via USB and make sure debugging is working; adb tcpip 5555 . This m...

 To test your applications in development over Wi-Fi



  1. Connect the device via USB and make sure debugging is working;
  2. adb tcpip 5555. This makes the device to start listening for connections on port 5555;
  3. Look up the device IP address with adb shell netcfg or adb shell ifconfig with Android 6.0 and higher;
  4. You can disconnect the USB now;
  5. adb connect <DEVICE_IP_ADDRESS>:5555. This connects to the server we set up on the device on step 2;
  6. Now you have a device over the network with which you can debug as usual.


To switch the server back to the USB mode, run adb usb, which will put the server on your phone back to the USB mode. If you have more than one device, you can specify the device with the -s option: adb -s <DEVICE_IP_ADDRESS>:5555 usb

To find the IP address while using OSX run the command adb shell ip route.

Forum Post : XDA Link

 Some of the Live Templates of Android Studio for speed coding are collected here. These are meant for Quick reference. newInstance  - Gener...

 Some of the Live Templates of Android Studio for speed coding are collected here.

These are meant for Quick reference.




  • newInstance - Generates the static newInstance function inside a Fragment

  • Toast - Generates Toast.makeText(context, "", Toast.LENGTH_SHORT).show();

  • fbc - findViewById with cast

  • const - Define a android style int constant

  • logd - Generates Log.d(TAG, "");

  • logm - Log current method name and its arguments.

  • logr - Log result of the current method

  • logt - static logtaf with current classname

  • psf - public static final

  • sout - Prints a string to System.out

  • soutm - Prints current class and method names to System.out

  • soutp - Prints method parameter names and values to System.out

  • visible - Set view visibility to VISIBLE

  • gone - Set view visibility to GONE

  • noInstance - private empty constructor to prohibit instance creation

We can create more as per our use cases.

List of all Live Templates here!!




Icons made by Freepik from www.flaticon.com



It is often required to use digital signature implementation in various projects. In this guide I'm posting simple steps to generate a k...

It is often required to use digital signature implementation in various projects. In this guide I'm posting simple steps to generate a key pair or import a certificate to a Keystore using keytool.

Make sure that you have JDK installed and path for jdk is set in Environment Variables.

Note : If path is not set then follow these steps from /jdk/bin/ directory.



Create a Private/Public Key Pair with Keytool

1. Run the below command to specify or create the keystore.

keytool -genkey -alias teiid -keyalg RSA -validity 365 -keystore server.keystore -storetype JKS

-alias : Name to identify in keystore

-keylag : Algorithm to be used in key generation

-keystore : The name of the keystore with type .jks

2. If the specified keystore already exists, enter the existing password for that keystore, otherwise enter a new password:

Enter keystore password: <password>

3. Answer the following questions when prompted:

What is your first and last name?
[Unknown]:  <user's name>
What is the name of your organizational unit?
[Unknown]:  <department name>
What is the name of your organization?
[Unknown]:  <company name>
What is the name of your City or Locality?
[Unknown]:  <city name>
What is the name of your State or Province?
[Unknown]:  <state name>
What is the two-letter country code for this unit?
[Unknown]:  <country name>

Note : It is adviced to set first and last name/CN(common name) as domain name or IP address of host machine.

4. Enter yes to confirm the provided information is correct:

Is CN=<user's name>, OU=<department name>, O="<company name>",
L=<city name>, ST=<state name>, C=<country name>  correct?
[no]:  yes

5. Enter your desired keystore password:

Enter key password for <server>
(Return if same as keystore password)

With above steps server.keystore file contains the newly generated public and private key pair.

Import public key certificate in keystore

Another common requirement is to export and import .cer public key certificate in trusted keystore.

Export:

keytool -v -export -file public.cer -keystore server.jks -alias alias

Import:

keytool -import -alias alias -file public.cer -keystore server.jks

Keytool is a utility in jdk/bin/ directoty. If jdk path is not set in environment variables then run below commands directly from that direc...

Keytool is a utility in jdk/bin/ directoty. If jdk path is not set in environment variables then run below commands directly from that directory.

use ./keytool if running in linux distributions.



Generate a Java keystore and key pair
keytool -genkey -alias mydomain -keyalg RSA -keystore keystore.jks -keysize 2048


Generate a keystore and self signed certificate
keytool -genkey -keyalg RSA -alias selfsigned -keystore keysto­re.jks -storepass password -validity 360 -keysize 2048


Generate a certificate signing request (CSR) for an existing Java keystore

keytool -certreq -alias mydomain -keystore keysto­re.jks -file mydoma­in.csr

Import a root or intermediate CA certif­icate to an existing Java keystore

keytool -import -trustcacerts -alias root -file Thawte.crt -keystore keystore.jks


Import a signed primary certificate to an existing Java keystore

keytool -import -trustcacerts -alias mydomain -file mydomain.crt -keystore keystore.jks


Import New CA into Trusted Certs

keytool -import -trustcacerts -file /path_to_ca.pem -alias CA_ALIAS -keystore $JAVA_HOME/jre/lib/security/cacerts


Check a standalone certificate

keytool -printcert -v -file mydomain.crt


Check which certificates are in a Java keystore

keytool -list -v -keystore keystore.jks


Check a particular keystore entry using an alias

keytool -list -v -keystore keystore.jks -alias mydomain


List Trusted CA Certs

keytool -list -v -keystore $JAVA_HOME/jre/lib/security/cacerts


Delete a certif­icate from a Java Keytool keystore

keytool -delete -alias mydomain -keystore keystore.jks


Change a Java keystore password

keytool -storepasswd -new new_storepass -keystore keystore.jks


Note: To access the keystore contents, password will be prompt and it must be provided.