This file contains 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.example.featureflaglibrary | |
import android.content.Context | |
import com.example.featureflaglibrary.FeatureFlagManager | |
class FeatureFlagProvider { | |
lateinit var flagManager: FeatureFlagManager | |
fun init(applicationContext: Context) { | |
flagManager = FeatureFlagManager() |
This file contains 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.example.featureflaglibrary | |
import android.content.Context | |
import android.content.SharedPreferences | |
class FeatureFlagManager : FeatureFlag { | |
lateinit var sharedPref: SharedPreferences | |
companion object { | |
const val feature = "feature" |
This file contains 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
interface FeatureFlag { | |
fun setKeyValue(key: String, value: Boolean) | |
fun getValue(key: String): Boolean | |
} |
This file contains 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
boolean permissionAccessCoarseLocationApproved = | |
ActivityCompat.checkSelfPermission(this, | |
permission.ACCESS_COARSE_LOCATION) == | |
PackageManager.PERMISSION_GRANTED; | |
if (permissionAccessCoarseLocationApproved) { | |
// App has permission to access location in the foreground. Start your | |
// foreground service that has a foreground service type of "location". | |
} else { | |
// Make a request for foreground-only location access. |
This file contains 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
<service | |
android:name="MyNavigationService" | |
android:foregroundServiceType="location" ... > | |
... | |
</service> |
This file contains 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
WorkManager.getInstance() | |
.beginWith(workRequest) | |
.then(workRequest1) | |
.then(workRequest2) | |
.enqueue(); |
This file contains 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
final PeriodicWorkRequest periodicWorkRequest | |
= new PeriodicWorkRequest.Builder(MyWorker.class, 10, TimeUnit.HOURS) | |
.build(); |
This file contains 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
WorkManager.getInstance().cancelWorkById(workRequest.getId()); |
This file contains 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
//creating constraints | |
Constraints constraints = new Constraints.Builder() | |
.setRequiresCharging(true) // you can add as many constraints as you want | |
.build(); | |
final OneTimeWorkRequest workRequest = | |
new OneTimeWorkRequest.Builder(MyWorker.class) | |
.setInputData(data) | |
.setConstraints(constraints) | |
.build(); |
This file contains 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
final TextView textView = findViewById(R.id.textViewStatus); | |
WorkManager.getInstance().getWorkInfoByIdLiveData(workRequest.getId()) | |
.observe(this, new Observer<WorkInfo>() { | |
@Override | |
public void onChanged(@Nullable WorkInfo workInfo) { | |
//receiving back the data | |
if(workInfo != null && workInfo.getState().isFinished()) | |
textView.append(workInfo.getOutputData().getString(MyWorker.TASK_DESC) + "\n"); | |
textView.append(workInfo.getState().name() + "\n"); |
NewerOlder