SubscriptionManager.from() Deprecated
Asked Answered
K

1

6

Previously we used to get instance of SubscriptionManager using

SubscriptionManager subscriptionManager=SubscriptionManager.from(this);

butSubscriptionManager.from(context) is deprecated in API 28 , what's the new way to get SubscriptionManager instance ?

Kyl answered 28/9, 2018 at 11:49 Comment(0)
K
18

We can get instance of SubscriptionManager using following way

Java

 SubscriptionManager subscriptionManager= (SubscriptionManager) getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);

or

SubscriptionManager subscriptionManager=getSystemService(SubscriptionManager.class);

for API>=23

Kotlin

val subscriptionManager = getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE) as SubscriptionManager

or

var subscriptionManager = getSystemService(SubscriptionManager::class.java)

Official Documentation

Kyl answered 28/9, 2018 at 11:49 Comment(1)
Thanks for sharing 🙂Natheless

© 2022 - 2024 — McMap. All rights reserved.