Skip to content

Instantly share code, notes, and snippets.

View Lavanyagaur22's full-sized avatar
🚩

Lavanya gaur Lavanyagaur22

🚩
View GitHub Profile
val result = detector.processImage(image)
.addOnSuccessListener { firebaseVisionText ->
// Task completed successfully
// ...
}
.addOnFailureListener { e ->
// Task failed with an exception
// ...
}
val image = FirebaseVisionImage.fromMediaImage(mediaImage, rotation)
private class YourImageAnalyzer : ImageAnalysis.Analyzer {
private fun degreesToFirebaseRotation(degrees: Int): Int = when(degrees) {
0 -> FirebaseVisionImageMetadata.ROTATION_0
90 -> FirebaseVisionImageMetadata.ROTATION_90
180 -> FirebaseVisionImageMetadata.ROTATION_180
270 -> FirebaseVisionImageMetadata.ROTATION_270
else -> throw Exception("Rotation must be 0, 90, 180, or 270.")
}
override fun analyze(imageProxy: ImageProxy?, degrees: Int) {
val json = prefs.getString("MyObject", "")
//returns the object of MyObject class that was saved earlier
val obj = gson.fromJson(json, MyObject::class.java)
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();
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
//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()
private lateinit var sensorManager: SensorManager
...
sensorManager = getSystemService(Context.SENSOR_SERVICE) as SensorManager
// 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)
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")