私はモノドロイドのためにおもちゃのインテントサービスを実行しようとしていて、本質的にこのソースマテリアルから外れていますが、いくつかの問題があり、放送受信機に届きました。何よりも私は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<Button>(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<TextView>(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<TextView>(Resource.Id.status);
txtView.Text = intent.GetStringExtra(TestIntentService.PARAM_OUT_MSG).ToString();
Toast.MakeText(context, "On Receive complete!", ToastLength.Short).Show();
}
}
}
}
- 私はそれを間違っていますか?私は閉じていますか?私はかなり近いと思いたいのですが、どうしても、私がtimbucktooにいるなら、私は知りたいです...
- もしそうなら、そのブロードキャストを送受信するための正しい方法は何ですか?