Xamarin Android BroadcastReceiver and SendRequest
 
Creating Receiver/Listelener class "MyBroadcastReceiver.cs"
"Important":  The "namespace" name of the listener class must be the same as the application package name. 
	namespace com.app.mypackagename
	{

		/// Create a Receiver
		[BroadcastReceiver(Enabled = true, Exported = true)]
		[IntentFilter(new[] { "MyReceiverAction1" })] 
		public class MyBroadcastReceiver : BroadcastReceiver
		{
			public override void OnReceive(Context context, Intent intent)
			{
				string getValue = intent.GetStringExtra("key1");

			}
		}
    }
	
Send BroadcastReqeust to Xamarin from Java Code 

	String xamarinAppBroadcastReceiverActionName = "MyReceiverAction1";
	 
	Intent triggerXamarinAppIntent = new Intent(xamarinAppBroadcastReceiverActionName);
	triggerXamarinAppIntent.putExtra("key1", " Message OK!");

	/** FLAG_INCLUDE_STOPPED_PACKAGES: 	
		En: Allows the service to listen even if "Xamarin" application is not running.
		Tr: XAMARIN app runnig olmasa bile servisinin dinleme yapmasini saglar. 
	**/
	triggerXamarinAppIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);

	context.sendBroadcast(triggerXamarinAppIntent);

 

Author: Engin ATALAY
Date: 1.04.2020 10:52:59
View Count: 1900
 
 

COMMENTS
 
No comments yet. Be the first to comment who you are.
 
 
 
 
 
 
 
WRITE COMMENT
 
 
Your Name :
 
 
 
E-mail :
 
 
 
Your Message :
 
 
 
 
 
 
 
This project : ASP.NET MVC , RAZOR, Entity Framework , CSS , HTML , JQUERY(2.0.2) , AJAX the C# side-tier architecture was developed with logic.
 
Yukarı Çık