Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SubscriptionManager.from() Deprecated

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 ?

like image 642
Manohar Avatar asked Dec 13 '22 14:12

Manohar


1 Answers

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

like image 120
Manohar Avatar answered Dec 17 '22 22:12

Manohar