Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to src/MainActivity.ktimport android.content.res.Configuration import android.os.Bundle import android.widget.Toast import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) title = "KotlinApp" } override fun onConfigurationChanged(newConfig: Configuration) { super.onConfigurationChanged(newConfig) if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { ... Read More
This example demonstrates how to disable the back button in android while logging out the application using Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to src/MainActivity.ktimport android.os.Bundle import android.widget.Toast import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) } override fun onBackPressed() { Toast.makeText(applicationContext, "Disabled Back ... Read More
This example demonstrates how to implement Android imageView zoom-in and Zoom out using kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to src/MainActivity.ktimport android.os.Bundle import android.view.MotionEvent import android.view.ScaleGestureDetector import android.view.ScaleGestureDetector.SimpleOnScaleGestureListener import android.widget.ImageView import androidx.appcompat.app.AppCompatActivity import kotlin.math.max import kotlin.math.min class MainActivity : AppCompatActivity() { private lateinit var scaleGestureDetector: ScaleGestureDetector private var scaleFactor = 1.0f private lateinit var imageView: ImageView override fun ... Read More
This example demonstrates how to convert an image into a Base64 string on Android using Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to src/MainActivity.ktimport android.graphics.Bitmap import android.graphics.BitmapFactory import android.os.Bundle import android.util.Base64 import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import java.io.ByteArrayOutputStream class MainActivity : AppCompatActivity() { lateinit var textView: TextView override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) ... Read More
Push-Location command in PowerShell is used to push (add) the current location to the location stack (Last In First Out (LIFO) - queue) while the Pop-Location is to retrieve the last location from the stack.When the PowerShell console opens there are no locations set to the stack.PS C:\> Get-Location -Stack PS C:\>When you type the Push-Location command it performs two operations at a time. First, it saves the current location to the top of the stack, and second, it browse the path specified. If there is no path specified then it only moves the current location to the stack. For ... Read More
Set-Location command in PowerShell is used to set the location of the drive from the current directory. The drive could be the local drive, folder path, shared path, registry, or any environmental variable.This command is very useful while writing the script because many times we need multiple files from the same folder and each time we need to mention the full path. This command allows us to set the path at the beginning of the script and then we can directly browse the path from the current directly.Example 1 − The below command sets the location from the C: to ... Read More
Although DSC is a very large topic, we will quickly summarize it in this article with the needed concepts to what exactly it is and how we can implement it.PowerShell Desired State Configuration (DSC) is an Infrastructure automation tool and used for Infrastructure as a Code (Iaac). Besides, DSC can also be used as an Inventory management tool like to get the specific inventory from the servers if they exist or not. PowerShell and DSC both are different things. However, DSC can be implemented using PowerShell.PowerShell script uses Imperative model means we need to write the script how we will ... Read More
To convert the hashtable to the JSON format we can use the ConvertTo-Json command. First, we have the following hashtable,Example$Body = [PSCustomObject]@{ AppName = 'StorageXIO' AppID ='xo2ss-12233-2nn12' License = 'valid' }To convert the hashtable to the JSON format,$Body | ConvertTo-JsonOnce you run the above command, properties are converted to the JSON format.Output{ "AppName": "StorageXIO", "AppID": "xo2ss-12233-2nn12", "License": "valid" }
When we write a program, people from a non-programming background often expect to get much possible help related to the program. When we write the function and we declare the parameters, people who are unaware of what kind of input the parameter need, generally search for the help first using the Get-Help command and then they find only the parameters but not the description of it. For example, function TestFunct{ param( #16 Digit Application ID [parameter(Mandatory=$true)] [String]$AppID, #Date in the Unix Format - 2020-10-31T17:12:10+0530 [String]$Date ... Read More
To disable the local user on the windows OS using PowerShell, we can use the Disable-Localuser command provided by the local user name. In the below example, we are going to disable the local user called TestUser.Disable-LocalUser -Name TestUserIf we see the GUI, the user account is disabled.To enable the above user, we can use the Enable-LocalUser command.Enable-LocalUser -Name TestuserTo run the above command on the remote computer, we can use the Invoke-Command method. We need to make sure local user account exist on the remote computer.Invoke-Command -ComputerName Test1-Win2k12, Test1-Win2k16 -ScriptBlock{ Enable-Localuser -Name TestUser }Invoke-Command -ComputerName Test1-Win2k12, Test1-Win2k16 -ScriptBlock{ ... Read More