Skip to content

Instantly share code, notes, and snippets.

@eric-romero
eric-romero / saveGeolocation.diff
Created October 12, 2023 22:55
Save geolocation to record
diff --git a/force-app/main/default/lwc/editAccountRecord/editAccountRecord.html b/force-app/main/default/lwc/editAccountRecord/editAccountRecord.html
index 5c58aa1..8fc23c6 100644
--- a/force-app/main/default/lwc/editAccountRecord/editAccountRecord.html
+++ b/force-app/main/default/lwc/editAccountRecord/editAccountRecord.html
@@ -27,20 +27,6 @@
<!-- input fields -->
<lightning-input-field field-name={nameField}></lightning-input-field>
-
- <!-- Disable the button if LocationService isn't available -->
class MyActivity : Activity() {
override fun onResume() {
super.onResume()
// AppCenter stores the stack trace for previous crashes
if (Crashes.hasCrashedInLastSession().get()) {
val report = Crashes.getLastSessionCrashReport().get()
val oom = report.stackTrace.substringBefore("\n").contains("OutOfMemory")
if (oom) {
eventLogger.reportAppCrashFromOOM()
}
class MyWebViewClient : WebViewClient() {
@RequiresApi(Build.VERSION_CODES.O)
override fun onRenderProcessGone(view: WebView,
detail: RenderProcessGoneDetail): Boolean {
eventLogger.reportWebViewRenderProcessGone(detail.didCrash())
return super.onRenderProcessGone(view, detail)
}
...
}
class MyHybridExtension {
val job = SupervisorJob()
var scope = CoroutineScope(Dispatchers.IO + job)
@JavascriptInterface
fun getContact(contactId: String, callbackId: String) = scope.launch {
try {
val contact: String = fetchContact(contactId)
callback(callbackId, contact)
} catch (e: OutOfMemoryError) {
class MyActivity : Activity() {
override fun onTrimMemory(level: Int) {
super.onTrimMemory(level)
// Intermediate levels may be added later, so use ranged conditionals
if (level >= TRIM_MEMORY_COMPLETE ||
level in TRIM_MEMORY_RUNNING_CRITICAL until TRIM_MEMORY_UI_HIDDEN) {
imageCache.clear()
webAppMgr.onLowMemory(level)
eventLogger.reportLowMemory(level)
public abstract class SafeJobIntentService extends JobIntentService {
@Override
public void onCreate() {
super.onCreate();
if (Build.VERSION.SDK_INT >= 26) {
mJobImpl = new androidx.core.app.SafeJobServiceEngineImpl(this);
} else {
mJobImpl = null;
}
}
@Override
public void onActivityPaused(Activity activity) {
if (activity.getIntent() == null
|| !activity.getIntent().getBooleanExtra(BackgroundJobService.SKIP_BG_CHECK, false)) {
BackgroundJobService.enqueueWork(activity);
}
}
// Flag the current activity to skip background check upon pause
activity.getIntent().putExtra(BackgroundJobService.SKIP_BG_CHECK, true);
// Launch the Camera app to take a picture
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
activity.startActivityForResult(intent, ActivityRequests.TAKE_PICTURE_REQUEST);
public class BackgroundJobService extends JobIntentService {
public static final int JOB_ID = 1000;
public static volatile boolean shouldContinue = false;
private static final Object lock = new Object();
private static final long BACKGROUND_TIMEOUT_WAIT_MS = 5000;
final Handler mHandler = new Handler();
public static void enqueueWork(Context context) {
Intent bgJobService = new Intent(context, BackgroundJobService.class);
BackgroundJobService.enqueueWork(
<application
android:name=".DetectBackgroundApp"
...
>
...
<service
android:name=".BackgroundJobService"
android:permission="android.permission.BIND_JOB_SERVICE" />
...
</application>