Where do I put "IInAppBillingService.aidl" in a LibGDX project? - java

I've been trying to get IAP to work with my LibGDX game for Android for over 6 hours. First I tried to use gdx-pay, but sadly the documentation for it is very unclear to me and was therefore not able to get it to work.
Because my games are only for Android (for now) gdx-pay was overkill anyway, so I decided to directly implement Google Play IAP. I found a tutorial that is pretty clear, but sadly it doesn't explain where I should put the IInAppBillingService.aidl file.
I tried putting it in a newly created directory in the Android directory, namely /android/vending/billing, but that doesn't seem to work and the directory also doesn't show when I have my project view on Android.
I also tried creating a new package "andoird.vending.billing" in the java directory where the game package with the AndroidLauncher is in but that doesn't work either.
With both these methods I'm not able to import the class IabHelper in the following tutorial code which is in AndroidLauncher.java located in my game's package:
String base64EncodedPublicKey = "xxx";
// compute your public key and store it in base64EncodedPublicKey
mHelper = new IabHelper(this, base64EncodedPublicKey);
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
if (!result.isSuccess()) {
// Oh noes, there was a problem.
Log.d("IAB", "Problem setting up In-app Billing: " + result);
}
// Hooray, IAB is fully set up!
Log.d("IAB", "Billing Success: " + result);
}
});
Where (and how) am I supposed to put the "IInAppBillingService.aidl" file to be able to import the IabHelper class in my LibGDX project? If you have a clearer tutorial on gdx-pay or on a technique similar to the one I'm using now I would also appreciate it.
Thanks in advance!

Related

Unity AndroidJavaObject not working without showing errors

I have been trying to call a Java method in unity. Not working for me, even the simplest example from the docs
using System.Collections;
using UnityEngine;
public class ExampleClass : MonoBehaviour {
void Start () {
AndroidJavaObject jo = new AndroidJavaObject ("java.lang.String", "some string");
int hash = jo.Call<int> ("hashCode");
Debug.Log ("hash=" + hash);
}
}
Unity console prints hash=0, which is not the hash code for provided String. Even if I change and use java.lang.StringInvalidClass as class name, unity still reports same result to the console without notifying errors. I can even try to call toString, toStringa, toInvalid2 and they always return empty string without showing errors.
This is a brand new 2d project with only script displayed above, attached to camara object. I am using Ubuntu, Unity 2019.4 and project platform is Android.
Thanks for the assistance.
Answering myself after some time working with unity.
All examples in the web and unity documentation doesn't mention it, which is weird since it is something simple to mention and about confusions: code needs to run as an android application. Editor or even unity remote does not work, in order to use AndroidJavaObject and related classes, your code needs to run as an android application installed in the phone.

Citymaps questions on Android studio

I have some new questions in today's citymaps development.
In the Android studio,if I develop the code for citymap, there are always no logs showing but for others that does not happen. Why?
According to the citymaps official website, to create a map instance with CitymapsMapFragment, but in the sample project which citymaps provides, it uses SupportCitymapsMpaFragment ,What is the difference between them?
When the map is loading complete, is it automatically positioning to the current position or some other default position? Where is it?
If I open the GPS location,I can locate to the current position and show a blue arrow quickly, but too much power consumption,are there any other location way like network or base station location?
Code follows:
CitymapsMapFragment fragment = (CitymapsMapFragment)fragmentManager.findFragmentById(R.id.map);
if (fragment != null) {
fragment.setMapViewListener(this);
}
I did not find the fragment have the method setMapViewListener but setMapViewReadyListener,does it right?
Other code:
CitymapsMapView mapView = new CitymapsMapView(this, options, this);
When I add animate in additional methods like this:
mapView.setMapPosition(position, 300, new MapViewAnimationListener() {
#Override
public void onAnimationEnd(boolean completed) {
Log.d("SomeApp", "Move Complete!");
}
});
the project fails and exits,I tried to surround the code with try-catch block to catch exception for purpose, but nothing shows in logcat view. Why?
I am developer on the Citymaps project. I will do my best to answer all your questions
1) If you are not receiving log statements, this is likely an issue with your own application, IDE, or device configuration. In our own application, which uses the Citymaps SDK, we have no issues with logging.
2) Prior to using the Citymaps SDK, it is highly advisable that you familiarize yourself with fragments, but the short version is that SupportCitymapsMapFragment extends from the Fragment class in the v4 support library.
3) It is up to you to set the default position the map.
4) If you create a class which implements from the LocationSource interface, and then call mapView.setLocationSource, you can modify the behaviors of the map's location services. For an example, have a look at CitymapsLocationSource.java, which is the default implementation for this interface used by the SDK.
As for the exception you are having, you have not provided nearly enough information. Please show a stack trace, and I may be able to help.
Thank you for using our SDK, feel free to post again with any more questions.

URL code assistance please short code (Newbie Java programmer)

I'm using NetBeans and trying to make a Jbutton play this .wav file that I have located in the build/classes/shadow part of my project. I want the .Jar to build with the .wav file so I could download the .Jar file on another computer and press the button and the music will play. The music is not locating or starting I'm not sure which it is, also please be easy on the terminology I am very very new.
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:File Clap = new File("sanic.WAV");
display.setText("cum on step it up!!!");
}
public static void startMusic() {
{
try{
URL url = Shadow.class.getClassLoader().getResource("sanic.wav");
play(); // NetBeans says it cannot find the symbol for play.
}catch(Exception e){
}
}
}
I'm not sure in what part of your code are you using your URL... But I'd suggest you to use AudioInputStream...
Regarding the problem finding the file... I had implemented something similar some time ago, while checking the code I have in my HDD, I found that this made it for me:
URL url = Shadow.class.getResource(myfile.wav);
But nowadays, I prefer working with this:
InputStream resourceAsStream = Shadow.class.getResourceAsStream(myfile.wav);
Hope it helps for what you need to do.
Regards and... happy coding :)

Cannot find symbol class Intent

I am new in android development and coding java and xml.
but I was following this tutorial:
http://www.steventrigg.com/activities-and-the-action-bar-create-an-alarm-clock-in-android-tutorial-part-1/#comment-296
then I had this error when using Intent. The word "Intent" under switch became red and there is an error "cannot find symbol class Intent"
Can someone explain to me what is going on and how to solve this?
This is the last part of my code under AlarmListActivity.java
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
switch (item.getItemId()) {
case R.id.action_add_new_alarm: {
Intent intent = new Intent(this,
AlarmDetailsActivity.class);
startActivity(intent);
break;
}
}
return super.onOptionsItemSelected(item);
}
Look at your AlarmListActivity again and check the import statements at the top and make sure it includes the line:
import android.content.Intent;
If you intend to use any pre-existing classes that aren't part of the java.lang package, you generally have to import those classes. An Android Intent, for example, is a pre-built class, written by the Android development team, that allows for notification of other apps/activities. If you want to use Intent, you'd then have to import the package containing Intent.
When you write new Intent(), the compiler sees that you're requesting the construction of a new object, but because that object is not found in the java.lang package, it needs to know where to look for a blueprint to build that object. The import statement is the location of that blueprint.
I took a look at the tutorial and in the manner of experienced programmers, the author seems to have glossed over a few basic, but nonetheless, important things, such as the import statements that make his sample code work.
I had a same problem which I just resolved, by understanding how Android Studio indexes files, As you know Building an Android App is quite complicated process. So Android studio has some internal references which it keeps getting updated on change of every file that you have created.
I arrived at this post while searching for the solution,
This is how I got this problem
I usually wont create an activity under the main project package, I create sub packages to organize files as per the design pattern that I use, for eg If my APP name is com.example.testingaravind then inside that I usually create packages such as activites, services, models, managers etc ... So today I just created an activity first and then moved that activity into activites package via Android Studio, I started facing the same issue what you have described, Below was my source code
public class BootstrapActivity extends ActionBarActivity {
private static final String TAG = "BootstrapActivity";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bootstrap);
}
public void startServiceOnClickHandler(View view) {
Intent intent = new Intent(BootstrapActivity.this , AnalyzerService.class);
startService(intent);
}
}
In the method startServiceOnClickHandler it was showing an error saying,
"Cannot resolve constructor Intent" I searched a lot in google and found that
When I move a file from one package to other package, my manifest file wont get updated, in the manifest we mention the activity name and its package path in my case it should be
android:name=".activities.BootstrapActivity"
But it was
android:name=".BootstrapActivity"
Because of this, Android studio was unaware that a class called BootstrapActivity exists inside the activities folder,
This seems to be a bug in the way how android studio works. Android Studio has to update manifestfile when I move the activity class file from one package to another package.
I am posting this to help others who might arrive at this post with the similar usecase.
Check name in manifest file in activity tag specify correct package for example your
<activity
android:name="Your-Package.MainActivity"
android:exported="true" />
In second case If you are using kotlin class inside java class, after configuring kotlin in project can solve the project...

lwuit wizard and deploy

I am developing J2ME application with lwuit and Codenameone and created it in lots of time. After I created it I wanted to deploy it in some devices like Nokia, Samsung, LG and etc. that they supported MIDP. So I figure out Nokia devices run it with no error and Samsung and other companies devices have some problems that I can't understand why?!
So I tried different way of creating this application. I used Codenameone wizard with blank theme and manual template and then I tried to deploy it. Well, that right. I got success and it ran in Samsung devices too.
After that I tried to add some forms to "theme" in this appliaction and run it in simulator. I changed some code in my main class like this:
public class Main extends UIBuilder {
private Form current;
public void init(Object context) {
try{
Resources theme = Resources.openLayered("/theme");
UIManager.getInstance().setThemeProps(theme.getTheme(theme.getThemeResourceNames()[0]));
}catch(IOException e){
e.printStackTrace();
}
}
public void start() {
if(current != null){
current.show();
return;
}
Form hi = findMain();//new Form("Hi World");
//hi.addComponent(new Label("Hi World"));
hi.show();
}
public void stop() {
current = Display.getInstance().getCurrent();
}
public void destroy() {
}
public com.codename1.ui.Form findMain() {
return (com.codename1.ui.Form)findByName("Main", Display.getInstance().getCurrent());
}}
I got error when I ran it.
So this is my questions:
I created one application in Visual Mode of Codenameone.
How can I run it in Samsung and some other devices like Samsung (without opertaing system, just support java or MIDP)?
How can I change my Visual Mode application to Manual Mode in Codenameone?
Thanks in advance.
You are deriving from UIBuilder within the lifecycle class and trying to use a finder method on something that isn't showing yet. There is absolutely no way that your code works in the simulator and it is not the code that was generated by the wizard.
Thanks Shai. For creating I did hard coding and create all of forms one by one.
I implement base Form that derive from com.codenameone.ui.Form and every forms derive from base Form.

Categories