好的,所以我一直在尝试为monodroID essentially going off of this source material运行一个玩具意图服务,并且遇到了一些问题,并将其归结为广播接收器.我怀疑ACTION_RESP字符串还有更多.如果没有别的话,我当然可以忍受,也许是对它的确认,或者是设置接收机可以看到的动作的正确方法.
所以,这就是我到目前为止所拥有的…
我的专心服务
using System;using System.Collections.Generic;using System.linq;using System.Text;using AndroID.App;using AndroID.Content;using AndroID.OS;using AndroID.Runtime;using AndroID.VIEws;using AndroID.Widget;using AndroID.Util;namespace Mono_For_AndroID_Intent_Service{ [Service] public class TestIntentService : IntentService { public static String ParaM_IN_MSG = "imsg"; public static String ParaM_OUT_MSG = "omsg"; #region Constructor public TestIntentService() : base("TestIntentService") { } #endregion protected overrIDe voID OnHandleIntent(Intent intent) { string msg = intent.GetStringExtra(ParaM_IN_MSG); //Do Stuff string result = msg + " " + DateTime.Now.ToString(); Intent broadcastIntent = new Intent(this,typeof(Mono_For_AndroID_Intent_Service.MainActivity.MybroadcastReceiver)); broadcastIntent.SetAction(Mono_For_AndroID_Intent_Service.MainActivity.MybroadcastReceiver.ACTION_RESP); broadcastIntent.Addcategory(Intent.categoryDefault); broadcastIntent.PutExtra(ParaM_OUT_MSG,result); Sendbroadcast(broadcastIntent); } }}
主要活动和广播接收器
using System;using AndroID.App;using AndroID.Content;using AndroID.Runtime;using AndroID.VIEws;using AndroID.Widget;using AndroID.OS;namespace Mono_For_AndroID_Intent_Service{ [Activity(Label = "Mono_For_AndroID_Intent_Service", MainLauncher = true, Icon = "@drawable/icon")] public partial class MainActivity : Activity { private MybroadcastReceiver Receiver; protected overrIDe voID OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our vIEw from the "main" layout resource SetContentVIEw(Resource.Layout.Main); IntentFilter filter = new IntentFilter(MybroadcastReceiver.ACTION_RESP); filter.Addcategory(Intent.categoryDefault); Receiver = new MybroadcastReceiver(); RegisterReceiver(Receiver, filter); var button = FindVIEwByID(Resource.ID.start); button.Click += (s,e)=> { Intent msgintent= new Intent(this,typeof(TestIntentService)); msgintent.PutExtra(TestIntentService.ParaM_IN_MSG,"Me message, arh"); Toast.MakeText(this, "Starting intent service!", ToastLength.Short).Show(); StartService(msgintent); }; TextVIEw txtVIEw = FindVIEwByID(Resource.ID.status); } public class MybroadcastReceiver : broadcastReceiver { public static Readonly string ACTION_RESP = "Mono_For_AndroID_Intent_Service.Intent.Action.MESSAGE_PROCESSED"; public overrIDe voID OnReceive(Context context, Intent intent) { Toast.MakeText(context, "Firing On Receive!", ToastLength.Short).Show(); var activity = (MainActivity)context; TextVIEw txtVIEw = activity.FindVIEwByID(Resource.ID.status); txtVIEw.Text = intent.GetStringExtra(TestIntentService.ParaM_OUT_MSG).ToString(); Toast.MakeText(context, "On Receive complete!", ToastLength.Short).Show(); } } }}
>我做错了吗?我靠近吗?我想以为我已经很近了,但是如果我真的在timbucktoo的话,我一定想知道…
>如果是这样,发送和接收该广播的正确方法是什么?
解决方法:
如果要在系统中注册广播接收器,则需要添加[broadcastReceiver]属性.
样品:
https://github.com/xamarin/monodroid-samples/blob/master/ApiDemo/App/OneShotAlarm.cs
总结以上是内存溢出为你收集整理的android-Monodroid意向服务的BroadcastReciever不触发OnReceive全部内容,希望文章能够帮你解决android-Monodroid意向服务的BroadcastReciever不触发OnReceive所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)