Skip to main content

Posts

android kotlin - AlertDialog multiple choice example

AlertDialog Multiple Choice The AlertDialog is a subclass of Dialog that can display buttons, a simple text message, a list of items, single-choice items, multiple-choice items, etc. Developers can display a more complex View on the alert dialog window using a custom View. The following android application development tutorial will demonstrate to us how we can display a list of multiple choice items in the alert dialog window as the content. And how developers can be notified when users select items from the multiple choice items list via the supplied listener. Android developers can add a click listener for the alert dialog multiple choice list items. To create an alert dialog developers have to initialize an instance of AlertDialog.Builder object. This AlertDialog Builder object can define the alert dialog’s various properties such as button, message, icon, list and etc. Finally, they can create an AlertDialog using this builder instance. ...

android kotlin - AlertDialog setSingleChoiceItems example

AlertDialog setSingleChoiceItems() The AlertDialog is a subclass of Dialog that can display buttons, a simple text message, a list of items, single-choice items, multiple-choice items, etc. Developers can display a more complex View on the alert dialog window using a custom View. The following android application development tutorial will demonstrate to us how we can display a list of single-choice items in the alert dialog window as the content. And how developers can be notified when users select an item from the single choice items list via the supplied listener. Android developers can add a click listener for the alert dialog single-choice list items. To create an alert dialog developers have to initialize an instance of AlertDialog.Builder object. This AlertDialog Builder object can define the alert dialog’s various properties such as button, message, icon, list and etc. Finally, they can create an AlertDialog using this builder instance. ...

android kotlin - AlertDialog setItems example

AlertDialog setItems() The AlertDialog is a subclass of Dialog that can display one, two, or three Buttons. It can display a text message. Developers can display a more complex View on the alert dialog window using a custom View.Android developers even can display a list of items inside an alert dialog window. The following android application development tutorial will demonstrate to us how we can display a list of items in the alert dialog window as the content. And how developers can be notified when users select an item from the list via the supplied listener. Android developers can add a click listener for the alert dialog list items. To create an alert dialog developers have to initialize an instance of AlertDialog.Builder object. This AlertDialog Builder object can define the alert dialog’s various properties such as button, message, icon, list and etc. Finally, they can create an AlertDialog using this builder instance. So how can...

android kotlin - WebView image download example

MainActivity.kt package com.cfsuman.kotlinexamples import android.Manifest import android.content.Context import android.graphics.Bitmap import android.support.v7.app.AppCompatActivity import android.os.Bundle import android.widget.Toast import kotlinx.android.synthetic.main.activity_main.* import android.os.Build import android.view.View import android.app.DownloadManager import android.content.pm.PackageManager import android.net.Uri import android.os.Environment import android.webkit.* import android.webkit.WebView import android.view.ContextMenu class MainActivity : AppCompatActivity() { private val url = "https://www.google.com" private val PermissionsRequestCode = 123 private lateinit var managePermissions: ManagePermissions override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) // Initialize a list of required permissions to request runtime ...

android kotlin - WebView file download example

MainActivity.kt package com.cfsuman.kotlinexamples import android.Manifest import android.content.Context import android.graphics.Bitmap import android.support.v7.app.AppCompatActivity import android.os.Bundle import android.widget.Toast import kotlinx.android.synthetic.main.activity_main.* import android.os.Build import android.view.View import android.app.DownloadManager import android.net.Uri import android.os.Environment import android.webkit.* class MainActivity : AppCompatActivity() { private val url = "https://en.savefrom.net/" private val PermissionsRequestCode = 123 private lateinit var managePermissions: ManagePermissions override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) // Initialize a list of required permissions to request runtime val list = listOf<String>( Manifest.permission.WRITE_EXTERNAL_STORAGE ) ...

android kotlin - WebView example

MainActivity.kt package com.cfsuman.kotlintutorials import android.app.Activity import android.content.Context import android.graphics.Bitmap import android.os.Build import android.os.Bundle import android.view.View import android.webkit.WebChromeClient import android.webkit.WebSettings import android.webkit.WebView import android.webkit.WebViewClient import android.widget.Button import android.widget.ProgressBar import android.widget.Toast import androidx.appcompat.app.AlertDialog class MainActivity : Activity() { lateinit var webView:WebView private val url = "https://www.android--code.com" override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) // Get the widgets references from XML layout webView = findViewById(R.id.webView) val buttonLoad: Button = findViewById(R.id.buttonLoad) val buttonBack: Button = findViewById(R.id.buttonBack)...

Android kotlin: How to request permissions at runtime

Introduction This code demonstrates how to request permissions at runtime in an Android application written in Kotlin. The Android operating system introduced runtime permissions in Android Marshmallow (API level 23). This means apps no longer get granted all permissions they declare in the manifest file at install time. Instead, the app must explicitly request permissions from the user when it needs to access sensitive features or data on the device. Breakdown of the Code The code consists of three main parts: MainActivity.kt: This file contains the main activity class for the application. It defines a button that the user can click to initiate the permission request process. It also handles the result of the permission request. ManagePermissions.kt: This file defines a separate class called ManagePermissions that encapsulates the logic for checking permissions, requesting permissions, and processing the permission request result. This class promotes better code orga...