Skip to content

Latest commit

 

History

History
68 lines (49 loc) · 2.11 KB

olusturma.md

File metadata and controls

68 lines (49 loc) · 2.11 KB
description
Android üzerinde haber (Broadcast) oluşturma

🏗️ Oluşturma | Broadcast

👀 Metotlara Göz Atma

🎈 Normal Broadcast

  • 🌃 Sırasız olarak tüm uygulamalara duyurulan haber yapısıdır
public void sendBroadcast() {
   Intent intent = new Intent();
   intent.setAction("com.example.myproject.ACTION_SHOW_TOAST");
   // Set the optional additional information in extra field.
   intent.putExtra("data","This is a normal broadcast");
   sendBroadcast(intent);
}

🚄 Ordered Broadcast (Sıralı)

  • 🚩 XML üzerinde belirlenenandroid:priority sırasına göre uygulamalara haber verir
  • 🎲 Birden fazla aynı android:priority değerine sahip uygulamalara için seçim rastgele olur
  • 👨‍💼 Her duyuru alan uygulama, intent verisini değiştirme hatta silme hakkına sahiptir
public void sendOrderedBroadcast() {
   Intent intent = new Intent();

   // Set a unique action string prefixed by your app package name.
   intent.setAction("com.example.myproject.ACTION_NOTIFY");
   // Deliver the Intent.
   sendOrderedBroadcast(intent);
}

🏘️ Local Broadcast (Yerel)

  • 🏠 Sadece uygulama içerisinde haber salınır
  • 👮‍♂️ Daha güvenlidir, çünkü diğer uygulamalar erişemez
  • 📈 Daha verimlidir, tüm sisteme haber salmakla uğraşılmaz
LocalBroadcastManager.getInstance(this).sendBroadcast(customBroadcastIntent);

{% hint style="info" %} ‍🧙‍♂ Detaylı bilgi için Broadcasts alanına bakabilirsin. {% endhint %}

👮‍♂️ İzin Gerektirenler

  • 📝 Manifest dosyası üzerinde uses-permission ile izin alınması gerekir
  • 🚫 İzni olmayanlar uygulamaların erişmesi engellenir
sendBroadcast(new Intent("com.example.NOTIFY"),Manifest.permission.SEND_SMS);
<uses-permission android:name="android.permission.SEND_SMS"/>