LibGDX inside Android Activity - android

I'm in the middle of developing a small app for Android using the Android UI and activities for the most part of the interaction, however one key aspect requires the use of LibGDX (using 3D models and physics). I want to be able to click a button in my app (my "Activate" class) which will open the "AndroidApplication" class (my "Bobble" class) that initializes and runs all the LibGDX code.
My problem is that I can't use an "Intent" to start an AndroidApplication class (only an Activity as far as I can tell). I'm sure that people have had to work around this issue in the past so any help would be fantastic.
Here's my code so far:
public class Activate extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try
{
setContentView(R.layout.activate_screen);
Button b_Run = (Button) findViewById(id.bActiveRun);
b_Run.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent to_Bobble = new Intent(v.getContext(), Bobble.class);
startActivity(to_Bobble);
}
});
}
catch (Exception e)
{
Log.e("Activate", "Error in activity", e);
Toast.makeText(getApplicationContext(),
e.getClass().getName() + " " + e.getMessage(),
Toast.LENGTH_LONG).show();
}
}
}
public class Bobble extends AndroidApplication {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LifeCycle loop = new LifeCycle();
loop.ddgSettings = new ddgSystemSettings(this);
initialize(loop, false);
}
}

Ok I can now confirm that there is no issue at all with the above code. The issue was that I hadn't declared my "Bobble" class/file in the AndroidManifest file, and that was causing the runtime error.

Related

Pusher: Trigger pusher events from android app

In an android app I was able to subscribe to a pusher channel and log out the event data. So now I want to be able to trigger events from the same application. I don't find documentation relating to this on the web.
Am I missing something because I also have a node express app in which I'm able to trigger and subscribe to events in the same app.
Below is my code for the Android app, I'm looking to trigger an event in the "responseAFunc" function which is wired to a button click.
I have also left out the all import statements and package statements.
public class MainActivity extends Activity {
private Button responseA;
private ActivityMainBinding binding;
private Pusher pusher;
private Channel channel;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
responseA = binding.responseA;
PusherOptions options = new PusherOptions();
options.setCluster("eu");
pusher = new Pusher("*****************",options);
pusher.connect( new ConnectionEventListener() {
#Override
public void onConnectionStateChange(ConnectionStateChange change) {
Log.e("Pusher"," changed to " + change.getCurrentState());
}
#Override
public void onError(String message, String code, Exception e) {
Log.e("Pusher" ," connecting! msg:" + message + " " + code);
Log.e("Pusher", e.getMessage());
}
}, ConnectionState.ALL);
channel = pusher.subscribe("to-pusher");
channel.bind("message", new SubscriptionEventListener() {
#Override
public void onEvent(PusherEvent event) {
Log.i("Pusher", event.getData());
}
});
}
public void responseAFunc(View view){
// Trigger event
}
}
Hope this makes sense and HELLO from South Africa !!!
Hello from Amsterdam!
What you are looking for is "client events". Here are the docs: https://pusher.com/docs/channels/using_channels/events/#triggering-client-events
It's very easy: Once you got an instance for a channel you can just call the "trigger" method on it. Here are the docs for java: https://github.com/pusher/pusher-websocket-java#triggering-events
The harder part is that it will only work on private and presence channels. And then you will need to implement authentication. https://pusher.com/docs/channels/server_api/authenticating-users/

Error At Android STUDIO

I'm learning to program for Android on the Android Studio .
When I start the application, the following message appears on the AVD " Unfortunalety , GuitarStoreV2 has stopped ."
Can anybody help me ?
(Sorry if some stupid mistake , do not have much familiarity with the language , and excuse the error Portuguese , because I am Brazilian and I do not speak English fluently )
Grateful for the attention
Mark Tonial
public class MainActivity extends AppCompatActivity {
Button btn_iniciaapp;
public void Inicia ()
{
Button btn_inciaapp = (Button) findViewById(R.id.btn_iniciaapp);
}
// Iniciando a tela de produtos
public void iniciaProd()
{
Intent ActivityProd = new Intent(this, ActivityProd.class);
startActivity(ActivityProd);
}
// Evento ao clicar no Botão
public void IniciaListener()
{
this.btn_iniciaapp.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
MainActivity.this.iniciaProd();
}
});
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.activity_main);
this.Inicia();
this.IniciaListener();
}
}
Button btn_iniciaapp;
public void Inicia ()
{
Button btn_inciaapp = (Button) findViewById(R.id.btn_iniciaapp);
}
Your program is likely crashing with a NullPointerException. Here, Inicia isn't setting the value of your class's btn_iniciaapp: it's creating a locally scoped Button which is shadowing your class's btn_iniciaapp. You're setting the value of the local Button, not the class's.
Since the class's btn_iniciaapp is never set, it remains null, and the call to this.btn_iniciaapp.setOnClickListener will trigger a NullPointerException.

How to create MobileFirst analytics log in native Android app?

I'm trying to write custom analytics log in native Android app. I don't see it in Analytics console. What could be wrong?
I use following code:
public void logEvent(View view) {
WLAnalytics.enable();
String json = "{\"package\": \"mfpStart\" }";
try {
WLAnalytics.log("Custom event", new JSONObject(json));
} catch (JSONException e) {
e.printStackTrace();
}
WLAnalytics.send();
}
Thanks in advance!
You have to make sure you are calling WLAnalytics.setContext(context) for example on your Activity's onCreate method do something like.
class YourActivity extends Activity {
public void onCreate(Bundle bundle) {
// other code
WLAnalytics.setContext(this);
}
}

sending data from one app to another app in android(AIR for ANDROID)

As we can send data from one Activity to another within the app and also from one app to another app by using Intent
I'm able to send data from my one app to another by using following code
just consider there are two apps APP1 and APP2 and I'm sending data from APP1 to APP2 and vice verse.
In APP1 package name: (com.sush.myApp)
public class HomeActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
// to receive data from com.my.demo package and display it to TextView
TextView mText = (TextView)findViewById(R.id.textView1);
String name=getIntent().getStringExtra("User_Message");
mText.setText(name);
// to send data from com.sush.myApp package to com.my.demo package
Button btn1 =(Button)findViewById(R.id.button1);
btn1.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
try
{
Intent i = new Intent(Intent.ACTION_MAIN);
PackageManager manager = getPackageManager();
i = manager.getLaunchIntentForPackage("com.my.demo");
i.putExtra("User_ID", "sush19");
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
}catch(Exception e)
{
e.printStackTrace();
Toast.makeText(v.getContext(), "App Not Found", Toast.LENGTH_LONG).show();
}
}
});
}
and from APP2 package name: (com.my.demo)
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// to receive data from com.sush.myApp package and display it to TextView
final TextView txt1 = (TextView)findViewById(R.id.Text1);
String name=getIntent().getStringExtra("User_ID");
txt1.setText(name);
// to send data from com.my.demo package to com.sush.myApp package
Button btnSending = (Button)findViewById(R.id.btnSend);
final EditText myMessage = (EditText)findViewById(R.id.txtMessage);
btnSending.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
if (myMessage.getText().toString().equals(""))
{
Toast.makeText(v.getContext(), "Enter your message", Toast.LENGTH_SHORT).show();
}
else
{
try
{
Intent i = new Intent(Intent.ACTION_MAIN);
PackageManager manager = getPackageManager();
i = manager.getLaunchIntentForPackage("com.sush.myApp");
i.putExtra("User_Message", myMessage.getText().toString());
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
}catch(Exception e)
{
e.printStackTrace();
Toast.makeText(v.getContext(), "Error: "+e, Toast.LENGTH_LONG).show();
}
}
}
});
}
And its working perfect..
Now my problem is I want to do same operation i.e sending data from one app to another but my first app is in Java created using Eclipse and my second app is in ActionScript created using AIR for Android in Adobe Flash Professional CS6
Is there a way to use Intent and PackageManager in Actionscript so that I can send the data easily from AIR app to Android App, if yes then can anyone show me a example
Or else can anyone show me an example on how to send data from Android App to AIR for Android App and vice verse..
Thank you...
There's 2 methods I can think of for this.
The first is to use the Java code you have written (or similar), package it as a Native Extension, and build that into your app.
Another alternative is to use a URI scheme and read the data from the InvokeEvent. This SO question covers that method already.

PayPal Integration with Android

I have seen some related questions but none focusing on the specific problem I have:
I'm using the PayPal MPL Library.
I build my PayPalPayment object, then create the activity for the checkout to occur. That runs fine. My problem is, on the ResultDelegate I need to call a function from my activity, that occurs after the payment and makes some changes (such as storing SharedPreferences, etc.).
So something like this:
public class ResultDelegate implements PayPalResultDelegate, Serializable {
public void onPaymentSucceeded(String payKey, String paymentStatus) {
System.out.println("SUCCESS, You have successfully completed your transaction.");
System.out.println("PayKey: "+payKey);
System.out.println("PayStatus: "+paymentStatus);
callMyCustomAfterPaymentFunction();
}
...
}
Now the thing is, I tried to create a constructor for ResultDelegate that accepts my activity. My existing code is:
//On the activity class
public class MainMenuActivity extends Activity {
public void onCreate(Bundle savedInstanceState)
{
...
Button buy = (Button) findViewByID(R.id.buy_button);
buy.setOnClickListener(new View.OnClickListener(){
public void onClick(View v)
{
new PurchaseTask(activity).execute();
}
}
}
}
public class PurchaseTask extends AsyncTask <String, Void, String> {
protected String doInBackground()
{
...
PayPal pp = PayPal.getInstance();
CheckoutButton cb = pp.getCheckoutButton(...);
cb.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
ResultDelegate delegate = new ResultDelegate(myActivity);
Intent checkout = PayPal.getInstance().checkout(paument, activity, delegate);
activity.StartActivity(checkoutIntent);
}
}
}
}
//On the ResultDelegate class
public class ResultDelegate implements PayPalResultDelegate, Serializable {
private Activity myActivity;
public void onPaymentSucceeded(String payKey, String paymentStatus) {
System.out.println("SUCCESS, You have successfully completed your transaction.");
System.out.println("PayKey: "+payKey);
System.out.println("PayStatus: "+paymentStatus);
myActivity.performAfterPaymentOperations();
}
...
}
So the goal is to call the activity function from the ResultDelegate. Or even simpler, just to be able to store some SharedPreference changes when the ResultDelegate onPaymentSucceeded() fires.
But I get a NotSerializableException mentioning that the my MyActivity field is not Serializable.
So, then I added the transient identifier to my activity field inside the ResultDelegate, but now I get a NullPointerException.
Paypal Mobile Chekout guide
Implementation provided on paypal website is different from yours. They are doing startActivityForResult() to start PaypalActivity. and when in onActivityResult() method they are checking statusCode to check transaction status and act accordingly.
Follow that document for your implementation.
Here in your code, I donot find a point for using AsyncTask. Your ResultDelegate is Serializable where as Activity is not thats why it is throwing NotSerializableException.
Edit:
As you are developing for Google Android platform, then why not to use Google Checkout In-App?
Edit:
This method will be called when your PaypalActivity will finish. That activity will pass resultCode to this onActivityResult method.
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (resultCode) {
case Activity.RESULT_OK:
// The payment succeeded
String payKey = data.getStringExtra(PayPalActivity.EXTRA_PAY_KEY);
// Tell the user their payment succeeded
break;
case Activity.RESULT_CANCELED:
// The payment was canceled
// Tell the user their payment was canceled
break;
case PayPalActivity.RESULT_FAILURE:
// The payment failed -- we get the error from the EXTRA_ERROR_ID
// and EXTRA_ERROR_MESSAGE
String errorID = data.getStringExtra(PayPalActivity.EXTRA_ERROR_ID);
String errorMessage = data
.getStringExtra(PayPalActivity.EXTRA_ERROR_MESSAGE);
// Tell the user their payment was failed.
}
}
regards,
Aqif Hamid
You can create you custom listener something like this :
Create a custom listener :
OnDoubleTap mListener;
// Double tap custome listenre to edit photoes
public interface OnDoubleTap {
public void onEvent(Uri imgPath, int mPos);
}
public void setDoubleTapListener(OnDoubleTap eventListener) {
mListener = eventListener;
}
Now call this wherever you want like this :
mListener.onEvent(Uri, 1));
Now whenever you call this listener this will fire in your activity where you use this listener like this :
myCanvas.setDoubleTapListener(new OnDoubleTap() {
#Override
public void onEvent(Uri imgPath, int Pos) {
// TODO Auto-generated method stub
Toast.makeText(mContext, "LISTENER WORKING !!!", Toast.LENGTH_SHORT).show();
}
});
Where myCanvas is object of class where you create you listener.
Try this solution:
PayPalPayment thingToBuy = new PayPalPayment(new BigDecimal(price),getResources().getString(R.string.curruncy_code), getResources().getString(R.string.app_name),
PayPalPayment.PAYMENT_INTENT_SALE);
Intent intent = new Intent(CreateEventStep4.this, PaymentActivity.class);
intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);
startActivityForResult(intent, REQUEST_PAYPAL_PAYMENT);
PaymentConfirmation confirm = data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
if (confirm != null) {
try {
Log.e("paymentExample", confirm.toJSONObject().toString());
JSONObject jsonObj=new JSONObject(confirm.toJSONObject().toString());
String paymentId=jsonObj.getJSONObject("response").getString("id");
System.out.println("payment id:-=="+paymentId);
screenShotFile = takeScreenshot(frmTemplate);
uploadImage(myEvent.getEvent_id(),screenShotFile);
} catch (JSONException e) {
Log.e("paymentExample", "an extremely unlikely failure occurred: ", e);
}

Categories

Resources