Android inapp billing - BillingService has compile errors with onServiceConnected and onServiceDisconnected - android

I am using the Dungeons application example and I am using the BillingService class provided in that example.
I am using Java 6 and #override works for me, but I get a compile error on these two methods inside BillingService.java:
/**
* This is called when we are connected to the MarketBillingService.
* This runs in the main UI thread.
*/
#Override
public void onServiceConnected(ComponentName name, IBinder service) {
if (Consts.DEBUG) {
Log.d(TAG, "Billing service connected");
}
mService = IMarketBillingService.Stub.asInterface(service);
runPendingRequests();
}
/**
* This is called when we are disconnected from the MarketBillingService.
*/
#Override
public void onServiceDisconnected(ComponentName name) {
Log.w(TAG, "Billing service disconnected");
mService = null;
}
Would someone help me understand why this is happening?
Thanks!

Make sure your class implements the ServiceConnection interface.

In App billing is a challenge to get started with. The trick is to get it started in a independent project and then do all your specific feature. Trust me on this, and done be brave and do it all together, its not worth the time it takes to get started. I hope google improves on in app billing overall, to make it easy to implement, understand and debug. I had blogged about it a while back and created a helloworld kinda project for people to download and get working. I hope it helps you too.
Debug Android inapp billing using Eclipse

I think you should simply remove the #Override decorator from both methods. I'm using the Google BillingService class and this is my method:
public void onServiceConnected(ComponentName name, IBinder service)
{
mService = IMarketBillingService.Stub.asInterface(service);
runPendingRequests();
}
You are implementing an interface, not extending a class with abstract methods.

You might try to use default compile options.
Right-click (or Control-Click) the project and select "Properties"
Select "Java Compiler"
Uncheck "Enable Project Specific Settings"
Eclipse will prompt to re-compile and it should be all good.

Install your app Signed ...so go to android tools export signed application .... now that its signed you can get back queries. This was my issue at least on a physical device.

Right click on the Project
Select --> Android Tools
Select --> Fix Project Properties
This fixed it for me (I believe it was a Java compiler setting throwing it off).

Related

AppsFlyer SDK Integration Test failed on app, but non-organic test data is reflected on the Dashboard

Trying to integrate the AppsFlyer SDK for Android, I've followed all the steps indicated in the AppsFlyer guide. Initially, the dependency that was stated is:
implementation 'com.appsflyer:af-android-sdk:4+#aar'
But for some reason, it wasn't pointing to the latest version on it's own, making the init() version not visible. And so I instead went ahead and adjusted it to version 4.8.15 (currently the latest version), which worked as expected in the guide.
After adding the required permissions (with the optional permission) and the BroadcastReceiver (I don't have any other receivers for the referrer so I only used the SingleInstallBroadcastReceiver), I implemented the initialization on the app's Application class like so:
public class MyApp extends Application {
private static final String AF_DEV_KEY = "DEV_KEY_FROM_CONSOLE_HERE";
#Override
public void onCreate() {
super.onCreate()
initAppsFlyer();
}
public void initAppsFlyer() {
final AppsFlyerConversionListener listener = new AppsFlyerConversionListener() {
#Override
public void onInstallConversionDataLoaded(Map<String, String> conversionData) {
}
#Override
public void onInstallConversionFailure(String errorMessage) {
}
#Override
public void onAppOpenAttribution(Map<String, String> attributionData) {
}
#Override
public void onAttributionFailure(String errorMessage) {
}
};
AppsFlyerLib.getInstance().init(AF_DEV_KEY, listener, this);
AppsFlyerLib.getInstance().startTracking(this);
}
}
The manifest is pointing to the MyApp application class for sure. So that's it. The initial setup is complete. Time for the SDK Integration test as per the guide.
So I installed the app directly from Android Studio to my device, downloaded SDK Integration test app, whitelisted the device, and selected the name of the app as mentioned in the test guide. Every step followed accordingly.
Clicked on SDK Integration Testing...
Checking configuration...
Testing your app..
*app opens*
*closes*
*opens again*
Testing your app..
Checking configuration...
..
X Oops..
This app can not be monitored. Please make sure that:
You are using a supported AppsFlyer SDK version.
AppsFyler's BroadcastReceiver is configured.
startTracking() is placed in the MainActivity
It's the latest version. So it should work.
Copy pasted the receiver. Tried removing it and then re-run the test, it showed the missing receiver error. Pasted it back in.
I'm calling startTracking() in the actual application class. But what the heck. I gave it a try, called it in the MainActivity.onCreate() same result.
I have no idea what is causing the failure in the test. Not much to go on from as well since there's no details on how to debug it further. However, I checked the Dashboard, and there it is. Non-Organic install data counted.
Now I'm confused. Is there an issue with the integration or with the SDK integration test app?

Why are references to the in-app billing classes not recognized by Ecliplse?

I am using this tutorial to implement in-app billing for an Android app. When I get to the section titled "Binding to IInAppBillingService" they provide a snippet like this:
IInAppBillingService mService;
ServiceConnection mServiceConn = new ServiceConnection() {
#Override
public void onServiceDisconnected(ComponentName name) {
mService = null;
}
#Override
public void onServiceConnected(ComponentName name,
IBinder service) {
mService = IInAppBillingService.Stub.asInterface(service);
}
};
And even though I installed the in-app billing library from my SDK manager, it doesn't seem to be recognizing the classes used in this snippet.
Am I maybe using a tutorial that isn't the most clear? Is there a better tutorial? This one seems to gloss over a few important details like where to get the actual class implementation for the referenced classes in that code.
Or do I just not have the libraries correctly configured?
Thank you!
Make sure you've copied <sdk>/extras/google/play_billing/IInAppBillingService.aidl file to your Eclipse project's src/com/android/vending/billing package. Then rebuild the project. Once you've done this, Eclipse will generate IInAppBillingService.java class and put it into gen folder of your project. Don't forget to import that java class and everything must compile.

embedded bonjour mdnsresponder for android not working (error -65563; daemon not running)

Since jmDNS does not support the service browse by subtypes, I went with cross compiling the bonjour for android, and I followed the below steps.
Cross compiled the mdnsresponder for android
Wrote dns-sd client with jni wrapper that uses the above shared library that has 2 jni functions:
One for calling the main loop
Another for browsing the services
I have written a java application with the wifi MulticastLock
But when I call the DNSServiceBrowse the error response I am getting is DNS service call failed -65563, "Background daemon is not running".
Generally while running on the linux we start mdns daemon.
How do I fix this problem? Any suggestions?
But when I call the DNSServiceBrowse the error response I am getting is DNS service call failed -65563, "Background daemon is not running".
You can't run daemons within Android. See: Android daemon process
In order to use the mdnsresponder in an embedded implementation, you must communicate with the mDNSCore directly. See the "How it Works" section of this ReadMe at [1].
How do I fix this problem?
Check out the "Note" section in mDNSEmbedded.h at [2] Basically rather than communicating through the daemon, you need to use the dnssd_clientshim.c at [3]. This allows you to "still use the preferred dns_sd.h APIs by linking in "dnssd_clientshim.c", which implements the standard "dns_sd.h" API calls, allocates any required storage using malloc(), and then calls through to the low-level malloc-free mDNSCore routines"
Note: It appears that the dnssd_clientshim.c has some spelling errors and missing reference that will prevent compiling so you need to perform a patch when building (see [4] & [5]). It also appears you still need to include dnssd_clientlib.c when compiling or you'll get build errors with TXTRecord function references.
[1]
[2]
[3]
[4]
[5]
it means you do not start the service yet when you get "DNS service call failed -65563".
there is a DNSSDEmbeddedDaemon class in the mdnsresponder package, you need to use this java class to start the daemon service first, then you can call browse() to find network services you want.
by the way, you need to acquire/release mutlti-cast lock for the daemon.
here is a section of sample code you may need, this is a service you start before browsing network service.
public class DNSSDEmbeddedDaemon extends Service {
private static final String TAG = DNSSDEmbeddedDaemon.class.getName();
public IBinder onBind(Intent paramIntent) {
return null;
}
public void onCreate() {
super.onCreate();
DNSSDEmbedded.listeners.clear();
DNSSDEmbedded.init(new DNSSDEmbedded.Listener() {
#Override
public void onStart() {
Log.d(TAG, "EmbededMDNS onStart");
}
#Override
public void onEnd() {
Log.d(TAG, "EmbededMDNS onEnd");
DNSSDEmbedded.listeners.clear();
}
#Override
public void onError() {
Log.d(TAG, "EmbededMDNS onError");
}
});
}
public void onDestroy() {
super.onDestroy();
Log.d(TAG, "EmbededMDNS Exit() is called");
DNSSDEmbedded.Exit();
}
}

In app billing in android

I am using following code:
public class MyBillingService extends Service implements ServiceConnection
{
String TAG = "MyBillingService";
#Override
public void onCreate()
{
super.onCreate();
Log.i(TAG, "onCreate");
try {
boolean bindResult = getBaseContext().bindService(
new Intent(IMarketBillingService.class.getName()), this, Context.BIND_AUTO_CREATE);
if (bindResult) {
Log.i(TAG, "Service bind successful.");
} else {
Log.e(TAG, "Could not bind to the MarketBillingService.");
}
} catch (SecurityException e) {
Log.e(TAG, "Security exception: " + e);
}
}
}
I have also added the IMarketBillingService.aidl but still it show like:
Could not bind to the
MarketBillingService
Can you point out my mistake?
I don't know if this is the cause for your problem, but you are using bindService() on getBaseContext(). Is there a reason that you don't call bindService() on the service instance? That's what the example service does.
The base context seems to be mostly unneeded and the general advice seems to not use it.
See the other question: What's the difference between the various methods to get a Context?
Besides that, you need to have the newest (or at least a recent) version of the Android Market App on your device, although I assume that it updates itself.
There is a way to test if the market app supports In-App Billing, somewhere described in the In-App-Billing reference. I assume that it is worth to do that check.
I was testing on an old Android device which had a clean system install. This didn't have a copy of the Google Market app on it (hat tip #sstn).
So I logged in with a Google account, then launched the Market. That prompted me to agree to terms and the Google Play app appeared in the list of applications.
Then I removed and reinstalled my app and it bound to the service correctly!

AIDL interface between two applications

I've stuck a total wall with the AIDL interfacing. I've an app which has to be controlled via 3rd party application (I've enough control over this so I can ask them to implement what ever I need into their activity)
Originally my app was also an activity with interface and everything but I've changed it to be a background service and for testing, I created a dummy app which manages to start the service app to the background.
Now I would like a way to request method calls from the service (mainly; start, stop, sendData). I've created the .aidl files for both apps. The aidl file implements only one method (this is courtesy of some other question here.)
package foo.testapp;
interface IScript
{
String executeScript(String script);
}
while the other aidl is same except the package is "foo.otherapp". The implementations I've found online had same package for both aidl files, but for me this causes an error (guess this is just a problem on my part since I hate namespaces and packages so I often just name them badly, if it's important to change them, I can do it)
The plan was to use this method to send a string to the service and just have a switch over predefined strings to call a correct method ( could also just implement three different methods if it improves the usage).
Anyway... I can't get the aidl to connect, I get error "Unable to start service intent
{act=foo.testapp.IScript } : not found
I would this guess has something to do with my misunderstandings ie. packagenames or so)
this is the implementation in my test activity app
private final IScript.Stub mBinder = new IScript.Stub()
{
#Override
public String executeScript(String script) throws RemoteException
{
// TODO Auto-generated method stub
}
};
IScript mService = null;
private ServiceConnection mConnection = new ServiceConnection()
{
public void onServiceConnected(ComponentName className, IBinder service)
{
mService = IScript.Stub.asInterface(service);
}
public void onServiceDisconnected(ComponentName className)
{
mService = null;
}
};
Then in OnCreate() method I'll do this:
bindService(new Intent(IScript.class.getName()),
mConnection, Context.BIND_AUTO_CREATE);
In service class I have this;
#Override
public IBinder onBind(Intent intent)
{
// Select the interface to return. If your service only implements
// a single interface, you can just return it here without checking
// the Intent.
if (IScript.class.getName().equals(intent.getAction()))
{
return mBinder;
}
return null;
}
/**
* The IRemoteInterface is defined through IDL
*/
private final IScript.Stub mBinder = new IScript.Stub()
{
#Override
public String executeScript(String script) throws RemoteException
{
if (script == "test")
{
return "foo";
}
return "fail";
}
};
And finally the manifest files;
well actually, I've no idea if I have to add something into manifest files when dealing with the aidl. In the one example I saw this;
<intent-filter>
<action android:name="foo.otherapp.IScript" />
</intent-filter>
and
<intent-filter>
<action android:name="foo.testapp.IScript" />
</intent-filter>
I would guess that the errors could be anywhere. I've been trying to set this up with chewing gum and band-aids. Guess I've just misunderstood some basic concept of this.
Anyway, any help is welcome.
Thanks in advance!
I decided to answer my own question since I found an exact solution.
My Life With Android
Everything worked just by copy pasting the source and changing the package names and function names correctly (assuming you're implementing this into your own project)
Source from client folder goes to the client activity and serviceimpl goes to service. I didn't need the 'Service activity', so I left it out ( and it doesn't really seem to be invoked anyway).
I don't have enough reputation to post multiple links, so you can get the source from the top of the page.
"Update: please check out the updated example program for Android SDK 1.5."
I struggled with this too. You are correct in your guess that the RemoteInterface.aidl needs to have the same package name in both the service and the test app - so where do you put it!?
If you are developing in Eclipse then the trick is to have a common source folder (common to both projects) Make this folder outside of both projects and in the build properties/source, click 'link source' and browse to the location of the common source. (You can call it any name you want) Do this in both projects and put the interface.aidl in there. It will appear in both projects' Package Explorer and when you change it in one project, the other will get updated too.
In the common source folder I put the interface.aidl in a package with the same name as the service.
If you are using Ant to build, the it gets a bit tricky as the default ant_rules.xml doesn't support two aidl folders, and you'll have to modify your build.xml quite a bit add a new target and all its dependencies.
I got my project going by adapting the samples form Chapter 17 from the 'download source' here:
link text

Categories

Resources