Hi Dan
I too am having a similar problem. I've converted all the java files to C#
and am now testing.
People on this forum can correct me here, but I believe you are
oversimplifying the casting like I initially did. I'm using license checking
code that I got back in January and a stub was created. Your
OnServiceConnected() should look like below:
public void OnServiceConnected(ComponentName name, IBinder service)
{
mService = BillingServiceStub.AsInterface(service);
}
The actual proxy code will be similar to below. I say similar because my
SendBillingRequest() with the reply variable is always null.
I learning heaps about Java here.
If you can find out where I went wrong I would love to learn. Below is the
code and proxy class for the IMarketBillingService (it's rough as I'm more
interested in getting the thing to work):
using Android.OS;
namespace com.android.vending.billing
{
internal interface IMarketBillingService : IInterface
{
/// <summary>
/// Given the arguments in bundle form, returns a bundle for
results.
</summary>
Bundle SendBillingRequest(Bundle bundle);
}
public abstract class BillingServiceStub : Binder, IMarketBillingService
{
private const string DESCRIPTOR =
"com.android.vending.billing.IMarketBillingService";
/** Construct the stub at attach it to the interface. */
public BillingServiceStub()
{
this.AttachInterface(this, DESCRIPTOR);
}
/**
* Cast an IBinder object into an IMarketBillingService interface,
* generating a proxy if needed.
*/
internal static IMarketBillingService AsInterface(IBinder obj)
{
if ((obj == null))
{
return null;
}
IInterface iin =
(IInterface)obj.QueryLocalInterface(DESCRIPTOR);
if (((iin != null) && (iin is BillingServiceStub)))
{
return ((BillingServiceStub)iin);
}
return new BillingServiceStub.Proxy(obj);
}
public IBinder AsBinder()
{
return this;
}
protected override bool OnTransact(int code, Parcel data, Parcel
reply, int flags)
{
switch (code)
{
case Binder.InterfaceConsts.InterfaceTransaction:
{
reply.WriteString(DESCRIPTOR);
return true;
}
case TRANSACTION_checkBilling:
{
data.EnforceInterface(DESCRIPTOR);
Bundle _arg0;
_arg0 = data.ReadBundle();
this.SendBillingRequest(_arg0);
return true;
}
}
return base.OnTransact(code, data, reply, flags);
}
const int TRANSACTION_checkBilling =
(Binder.InterfaceConsts.FirstCallTransaction + 0);
public abstract Bundle SendBillingRequest(Bundle bundle);
private class Proxy : Java.Lang.Object, IMarketBillingService
{
private IBinder mRemote;
public Proxy(IBinder remote)
{
mRemote = remote;
}
public IBinder AsBinder()
{
return mRemote;
}
public string GetInterfaceDescriptor()
{
return DESCRIPTOR;
}
public Bundle SendBillingRequest(Bundle bundle)
{
Parcel _data = Parcel.Obtain();
Parcel reply = null;
bool bRes = false;
try
{
_data.WriteInterfaceToken(DESCRIPTOR);
_data.WriteBundle(bundle);
bRes =
mRemote.Transact(BillingServiceStub.TRANSACTION_checkBilling, _data, reply,
TransactionFlags.Oneway);
}
finally
{
_data.Recycle();
}
return reply.ReadBundle();
}
}
}
}
--
View this message in context:
http://mono-for-android.1047100.n5.nabble.com/Binding-Services-casting-interface-on-service-connection-fails-tp5711549p5711551.html
Sent from the Mono for Android mailing list archive at Nabble.com.
_______________________________________________
Monodroid mailing list
[email protected]
UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid