This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun createNotificationChannel() { | |
// Create the NotificationChannel, but only on API 26+ because | |
// the NotificationChannel class is new and not in the support library | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | |
val name = getString(R.string.channel_name) //name of the channel | |
val descriptionText = getString(R.string.channel_description) | |
val importance = NotificationManager.IMPORTANCE_DEFAULT //importance of the channel | |
// Create a NotificationChannel | |
val channel = NotificationChannel(CHANNEL_ID, name, importance).apply { | |
description = descriptionText |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Create a simple notification, first - > Channel ID | |
val simpleNotification = NotificationCompat.Builder(this, "first") | |
.setSmallIcon(R.drawable.ic_launcher_foreground) | |
.setContentTitle("Hello There") | |
.setContentText("General Master!") | |
.setPriority(NotificationCompat.PRIORITY_DEFAULT).build() | |
//Show the notification, nm is the NotificationManager object | |
nm.notify(id, simpleNotification) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val bigTextStyle = NotificationCompat.Builder(this, "first") | |
.setSmallIcon(R.drawable.ic_launcher_foreground) | |
.setContentTitle("Hello There") | |
.setContentText("General Master!") | |
.setStyle( | |
NotificationCompat.BigTextStyle() | |
.bigText(getString(R.string.big_string)) | |
) | |
.setPriority(NotificationCompat.PRIORITY_DEFAULT).build() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val icon = BitmapFactory.decodeResource( | |
this.resources, | |
R.drawable.ic_launcher_foreground | |
) | |
val not = NotificationCompat.Builder(this, "first") | |
.setSmallIcon(R.drawable.ic_launcher_foreground) | |
.setContentTitle("Hello There") | |
.setContentText("General Kenobi!") | |
.setLargeIcon(icon) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val i = Intent() | |
i.action = Intent.ACTION_VIEW | |
i.data = Uri.parse("https://www.google.com") | |
val pi: PendingIntent = | |
PendingIntent.getActivity(this, 12345, i, PendingIntent.FLAG_UPDATE_CURRENT) | |
val actionedNotification = NotificationCompat.Builder(this, "first") | |
.setSmallIcon(R.drawable.ic_launcher_foreground) | |
.setContentTitle("Hello There") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create an intent | |
val i = Intent() | |
i.action = Intent.ACTION_VIEW | |
i.data = Uri.parse("https://www.google.com") | |
// Craete a pending intent | |
val pi: PendingIntent = | |
PendingIntent.getActivity(this, 12345, i, PendingIntent.FLAG_UPDATE_CURRENT) | |
val actionedNotification = NotificationCompat.Builder(this, "first") | |
.setSmallIcon(R.drawable.ic_launcher_foreground) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private lateinit var sensorManager: SensorManager | |
... | |
sensorManager = getSystemService(Context.SENSOR_SERVICE) as SensorManager |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//To get a list of all sensors present on the device. | |
val deviceSensors: List<Sensor> = sensorManager.getSensorList(Sensor.TYPE_ALL) | |
//To get the default gravity sensor present on the device | |
val gravSensor = sensorManager.getDefaultSensor(TYPE_GRAVITY) | |
//To check the power of the sensor if present | |
val power = gravSensor.getPower() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.lavanya.androidsensors | |
import android.content.Context | |
import android.graphics.Color | |
import android.hardware.Sensor | |
import android.hardware.Sensor.TYPE_GRAVITY | |
import android.hardware.Sensor.TYPE_PROXIMITY | |
import android.hardware.SensorEvent | |
import android.hardware.SensorEventListener | |
import android.hardware.SensorManager |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val myObject = MyObject() | |
//set variables of 'myObject', etc.. | |
// val editor = prefs.edit() -> gives the SharedPreferences.Editor | |
val gson = Gson(); | |
val json = gson.toJson(myObject); | |
editor.putString("MyObject", json); | |
editor.apply(); |