Android Question When set sdk34 in xamarin android project, gives error one of receiver_exported or receiver_not_exported should be specified

Status
Not open for further replies.

busra.guler

New Member
When I set the targetsdkversion to 34 in my Xamarin android project, the application crashes when opening and gives the following error: one of receiver_exported or receiver_not_exported should be specified when a receiver is not being registered exclusively for system broadcasts.

ToastNotification.Init(this); It gives this error in the section.
I guess I can't record the broadcast

OnCreate metodu:
protected override void OnCreate(Bundle savedInstanceState)
        {
    
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource = Resource.Layout.Toolbar;
  
      
            base.OnCreate(savedInstanceState);
            Instance = this;
         
            Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity = this;
            FirebaseApp.InitializeApp(this);
            Rg.Plugins.Popup.Popup.Init(this);
      
            this.Window.AddFlags(WindowManagerFlags.Fullscreen);
            //ZXing.Net.Mobile.Forms.Android.Platform.Init();
            var config = new FFImageLoading.Config.Configuration()
            {
                VerboseLogging = false,
                VerbosePerformanceLogging = false,
                VerboseMemoryCacheLogging = false,
                VerboseLoadingCancelledLogging = false,
                Logger = new CustomLogger(),
            };
            ImageService.Instance.Initialize(config);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);

            DependencyService.Register<ToastNotification>();

            IntentFilter filter = new IntentFilter(Intent.ActionRun);

            if (Build.VERSION.SdkInt >= BuildVersionCodes.Tiramisu)
            {
                Context context = Android.App.Application.Context;
                //IntentFilter filter = new IntentFilter(Intent.ActionRun);

                ContextCompat.RegisterReceiver(this, new MyBroadcastReceiver(), filter, ContextCompat.ReceiverExported);
            }
            else
            {
                RegisterReceiver(new MyBroadcastReceiver(), filter);
            }

            if (Build.VERSION.SdkInt >= BuildVersionCodes.Tiramisu)
            {
                // Eğer API 33 ve sonrası ise `ToastNotification`'ı initialize etmeden önce gerekli flag'i ekleyin
                ToastNotification.Init(this );  // veya ReceiverNotExported
            }
            else
            {
                ToastNotification.Init(this);
            }

            //RegisterReceiver(consoleCmdReceiver, new IntentFilter(Intent.ActionRun));
            //ToastNotification.Init(this,);
            CachedImageRenderer.Init(true);
            CachedImageRenderer.InitImageViewHandler();
 
            LoadApplication(new App());

            //string tkn= CrossFirebasePushNotification.Current.Token;

            //FirebasePushNotificationManager.ProcessIntent(this, Intent);

        }

broadcast record:
[BroadcastReceiver(Enabled = true, Exported = true)]
    public class MyBroadcastReceiver : BroadcastReceiver
    {
        public override void OnReceive(Context context, Intent intent)
        {
            if (intent.Action == Intent.ActionRun)
            {
                // İstediğiniz işlemleri burada yapabilirsiniz
                Android.Util.Log.Info("ConsoleCmdReceiver", "Received RUN intent");

                string message = intent.GetStringExtra("message");
                Android.Util.Log.Info("ConsoleCmdReceiver", $"Received message: {message}");

                Toast.MakeText(context, "Broadcast received!", ToastLength.Short).Show();
            }
        }
    }
 
Status
Not open for further replies.
Top