CATEGORIES
>>
Dart(2)
>>
Errors(5)
>>
Android(11)
>>
Errors(1)
>>
Errors(2)
>>
Windows 8(3)
>>
iPhone7(1)
>>
Errors(4)
>>
Html(1)
RECOMMENDED SITES
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.
"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: 2087
COMMENTS
No comments yet. Be the first to comment who you are.