Skip to content

Instantly share code, notes, and snippets.

View abircse's full-sized avatar
🏠
Working from My Workstation

Nayeem Shiddiki Abir abircse

🏠
Working from My Workstation
View GitHub Profile
fun printKeyHash(context: Activity): String? {
val packageInfo: PackageInfo
var key: String? = null
try {
//getting application package name, as defined in manifest
val packageName = context.applicationContext.packageName
//Retriving package info
packageInfo = context.packageManager.getPackageInfo(packageName,
PackageManager.GET_SIGNATURES)
@abircse
abircse / CustomDialogWithItemAction.kt
Last active March 17, 2021 14:20
CustomDialogWithItemAction
val options = arrayOf<CharSequence>("Share", "Copy URL","Cancel")
val builder = AlertDialog.Builder(this)
builder.setTitle("")
builder.setCancelable(false)
builder.setItems(options) { dialog: DialogInterface, item: Int ->
if (options[item].equals("Share")) {
val intent = Intent(Intent.ACTION_SEND)
intent.type = "text/plain"
intent.putExtra(Intent.EXTRA_TEXT, YOUR_LINK)
startActivity(Intent.createChooser(intent, "Share"))
@abircse
abircse / Speechtotext.kt
Created March 6, 2021 09:21
Speech to text converter android
/*
* Microphone Item click to record
*/
yourmicrophoneuicon.setOnClickListener {
// Get the Intent action
val sttIntent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
// Language model defines the purpose, there are special models for other use cases, like search.
sttIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM)
// Adding an extra language, you can use any language from the Locale class.
sttIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault())
@abircse
abircse / readHtmlFileinString.kt
Created March 6, 2021 07:42
ReadHtmlFileInText
fun readHtmlFile(section: String, fileName: String, context: Context): String? {
val returnString = StringBuilder()
var fIn: InputStream? = null
var isr: InputStreamReader? = null
var input: BufferedReader? = null
try {
fIn = context.resources.assets
.open(section + fileName)
isr = InputStreamReader(fIn)
input = BufferedReader(isr)
@abircse
abircse / SaveImageViewImageToGallery.kt
Last active March 6, 2021 13:08
SaveImageViewImageToGallery
fun saveImageToGallery(context: Context, fileName: String, photoView: PhotoView) {
val bitmapDrawable = photoView.drawable as BitmapDrawable
val bitmap = bitmapDrawable.bitmap
val filename = String.format("%s.png", fileName)
if (Build.VERSION.SDK_INT >= 29) {
val values = contentValues(filename)
values.put(MediaStore.Images.Media.RELATIVE_PATH, Environment.DIRECTORY_PICTURES + "/" + "YOUR_FOLDER_NAME")
values.put(MediaStore.Images.Media.IS_PENDING, true)
// RELATIVE_PATH and IS_PENDING are introduced in API 29.
@abircse
abircse / Converthtmlfiletotext.txt
Created February 17, 2021 06:03
Converthtmlfiletotext
val textView = findViewById<TextView>(R.id.textview)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
textView.text = Html.fromHtml(readTxt(), Html.FROM_HTML_MODE_LEGACY)
} else {
textView.text = HtmlCompat.fromHtml(readTxt()!!, HtmlCompat.FROM_HTML_MODE_LEGACY)
}
}
@abircse
abircse / MyFireBaseMessagingService.txt
Created February 15, 2021 14:00
MyFireBaseMessagingService
class MyFireBaseMessagingService : FirebaseMessagingService() {
var mtitle: String? = null
var mmessage: String? = null
override fun onMessageReceived(remoteMessage: RemoteMessage) {
super.onMessageReceived(remoteMessage)
mtitle = remoteMessage.data["title"]
mmessage = remoteMessage.data["message"]
showNotificationMessage(mtitle, mmessage)
}
@abircse
abircse / RandomCodeGeneratorInNumber.kt
Last active April 17, 2021 16:29
RandomCodeGeneratorInNumberUtils
object RandomIntGenerator {
fun generate(): Int {
val rnd = Random()
val number = rnd.nextInt(999999)
return number
}
}
@abircse
abircse / DistanceCalculationsUtils.txt
Created February 15, 2021 13:58
DistanceCalculationsUtils
object DistanceCalculations {
fun CalculationByDistance(StartP: LatLng, EndP: LatLng): Double {
val Radius = 6371 // radius of earth in Km
val lat1 = StartP.latitude
val lat2 = EndP.latitude
val lon1 = StartP.longitude
val lon2 = EndP.longitude
val dLat = Math.toRadians(lat2 - lat1)
val dLon = Math.toRadians(lon2 - lon1)
@abircse
abircse / DateTimeUtils.txt
Created February 15, 2021 13:56
DateTimeUtilsExtension
object DateTimeUtils {
fun convertDateToLong(date : String) : Long
{
val dateFormat = SimpleDateFormat("yyyy/MM/dd")
val date = dateFormat.parse(date)
val dateInLong = date.time
return dateInLong
}