Cihazımda X uygulaması kurulu mu ?

Kas 09, 2021
hamurcuabi

0 Yorum
828

Selamlar bugün sizlere çok kısa ama işe yarar bir bilgi vermek istiyorum. Bazen uygulamamıza ekstra bir uygulama ile bazı işlemler yaptırmak isteyebiliriz ama eğer cihazımızda uygulama yoksa ? Hadi bunun kontrolünü sağlayalım 🤩

Kendi yazdığım extension func kodlarını hemen göstereyim aslında gayet basit ama ekstra söyleceklerim de var tabi.

/**
 * Checks if package installed or not
 * @sample  isPackageInstalled("com.emrhmrc.testapp")
 */
fun Context.isPackageInstalled(packageName: String): Boolean {
    return try {
        packageManager.getPackageInfo(packageName, GET_META_DATA)
        true
    } catch (e: PackageManager.NameNotFoundException) {
        false
    }
}

Yukardaki extension func bütün projelerinizde kullanabilirsiniz. Peki ekstra olarak ne var ?

Uygulamanız Android 11 ve üstü destekliyorsa yukardaki kod yetersiz kalacaktır. Bunun için manifest.xml içine özel birşeyler yazmalıyız.

 <queries>
        <package android:name="com.emrhmrc.testapp" />
        <package android:name="com.example.store" />
        <package android:name="com.example.services" />
 </queries>

queries taglari arasına extra olan uygulamamızın package name'ini vermemiz gerekiyor. Birden çok eklyebiliyoruz.

Detaylı bili isteyenler için 🧐

Android 11 changes how apps can query and interact with other apps that the user has installed on a device. Using the new element, apps can define the set of other apps that they can access. This element helps encourage the principle of least privilege by telling the system which other apps to make visible to your app, and it helps app stores like Google Play assess the privacy and security that your app provides for users.
If your app targets Android 11, you might need to add the element in your app's manifest file. Within the element, you can specify apps by package name or by intent signature.
So you either have to stop what you are doing, or request to access information about certain packages, or - if you have reasons for it - use the permission QUERY_ALL_PACKAGES.

Bu yazı bu kadar olsun bu kısa yazılar büüyk sorunlarınızı çözer umarım mutlu günler 😊😊😊😊

android isappinstalled kotlin queries

Benzer Yazılar


Yorumlar