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 result = detector.processImage(image) | |
.addOnSuccessListener { firebaseVisionText -> | |
// Task completed successfully | |
// ... | |
} | |
.addOnFailureListener { e -> | |
// Task failed with an exception | |
// ... | |
} |
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 image = FirebaseVisionImage.fromMediaImage(mediaImage, rotation) |
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 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) { |
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 json = prefs.getString("MyObject", "") | |
//returns the object of MyObject class that was saved earlier | |
val obj = gson.fromJson(json, MyObject::class.java) |
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(); |
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
//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
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
// 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
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") |