Posts

DownloadManager

Example Code: MainActivity.java public class MainActivity extends AppCompatActivity { @Override protected void onCreate (Bundle savedInstanceState) { super .onCreate(savedInstanceState) ; ActivityMainBinding binding = ActivityMainBinding. inflate (getLayoutInflater()) ; setContentView(binding.getRoot()) ; configure(binding) ; } private void configure (ActivityMainBinding binding) { final String imageAddress = "https://images.unsplash.com/photo-1707343844152-6d33a0bb32c3?w=500&auto=format&fit=crop&q=60&ixlib=rb-4.0.3&ixid=M3wxMjA3fDF8MHxlZGl0b3JpYWwtZmVlZHwxfHx8ZW58MHx8fHx8" ; binding. btnDownload .setOnClickListener(view -> { DownloadManager.Request request = new DownloadManager.Request(Uri. parse ( imageAddress )) ; request.setTitle( "Image" ) ; request.setDescription( "Downloading..." ) ; request.setDestinationUri(Uri. fr

Comments in Android

Image
Introduction There are three types of comments you can use in Android Studio  Line Comment - // Block Comment - /* */ JavaDoc - /** */ This post is all about different tips and tricks which I found over the years of using JavaDocs from various projects. JavaDoc is a utility that Java, Android or Kotlin developers can use with the help of installed Java SDK to generate code documentation. This is a simple example of using JavaDoc comments in Android Studio. With the help of the JavaDoc comments defined for setStartTime method we can get this kind of information snippet Tips You can use a file of a project with another file with the help of @link annotation used in JavaDoc. Syntax is {@link FileName} /** * A ViewModel used for the { @link ChronoActivity2}. */ You can define parameter names of a method with the help of @param annotaion. e.g. * @param startTime value for startTime To Be Continued... Reference https://freakycoder.com/android-studio-tips-tricks-2-comments-shortcut-13b9

SSLSocketFactory in Android

Image
Overview SSLSocketFactory is used to create secure sockets. Steps to follow First you have to create a key store. Open command prompt using Administrator login. Type " cd C:\Program Files\Java\jdk-14\bin ". Type the below command keytool -genkey -v -keystore my-key.keystore -alias my-key-alias-keyalg RSA -keysize 2048 -validity 10000 Follow the steps given in the screenshot: For - keyalg you can use RSA, DSA, EC to generate asymmetric key pair or use DES, 3DES to generate symmetric key pair. Then you have to generate a certificate Open command prompt using Administrator login. Type " cd C:\Program Files\Java\jdk-14\bin ". Type the below command keytool -certreq -alias "my-key-alias" -file mycertreq.csr -keystore my-key.keystore Follow the steps given in the screenshot. Note: The password , alias name , keystore name must be the same which you used while creating the keystore . An example of creating a subclass of SSLSocketFactory class TLSSocketFact

Connectivity in Android

Image
Connect to the network To perform network operations in your application, your manifest must include the following permissions: < uses-permission android :name ="android.permission.INTERNET" /> < uses-permission android :name ="android.permission.ACCESS_NETWORK_STATE" /> Note: Both the Internet and ACCESS_NETWORK_STATE permissions are normal permissions , which means they're granted at install time and don't need to be requested runtime . Best practices for secure network communication Minimize the amount of sensitive or personal user data that you transmit over the network. Send all network traffic from your app over SSL . Consider creating a network security configuration , which lets your app trust custom certificate authorities (CAs) or restrict the set of system CAs that it trusts for secure communication. Follow networking security tips Choose an HTTP client Most network-connected apps use HTTP to send and receive data. The Android pla