This repository has been archived by the owner on Nov 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 473
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
4329: For #4113. Add extension method for creating service `PendingIntent`. r=rocketsroger a=dector Co-authored-by: Denys M <dector9@gmail.com>
- Loading branch information
Showing
4 changed files
with
33 additions
and
9 deletions.
There are no files selected for viewing
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
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
25 changes: 25 additions & 0 deletions
25
components/support/utils/src/main/java/mozilla/components/support/utils/intents.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
@file:JvmName("IntentUtils") | ||
|
||
package mozilla.components.support.utils | ||
|
||
import android.app.PendingIntent | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.os.Build | ||
|
||
/** | ||
* Create a [PendingIntent] instance to run a certain service described with the [Intent]. | ||
* | ||
* This method will allow you to launch a service that will be able to overpass | ||
* [background service limitations](https://developer.android.com/about/versions/oreo/background#services) | ||
* introduced in Android Oreo. | ||
* | ||
* @param context an [Intent] to start a service. | ||
*/ | ||
@JvmName("createForegroundServicePendingIntent") | ||
fun Intent.asForegroundServicePendingIntent(context: Context): PendingIntent = | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
PendingIntent.getForegroundService(context, 0, this, 0) | ||
} else { | ||
PendingIntent.getService(context, 0, this, 0) | ||
} |
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