Error during android build for native interface - android

I have implemented some native android paypal integration code under native interface in codenameone.
Call from codenameOne:
MyNative my = (MyNative)NativeLookup.create(MyNative.class);
In the Native Interface:
package com.mycompany.myapp;
import com.codename1.system.NativeInterface;
public interface MyNative extends NativeInterface{
}
I have given proper android.xapplication under build_hint and write android code under the impl class:
package com.mycompany.myapp;
import java.math.BigDecimal;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;
import com.paypal.android.sdk.payments.PayPalAuthorization;
import com.paypal.android.sdk.payments.PayPalConfiguration;
import com.paypal.android.sdk.payments.PayPalFuturePaymentActivity;
import com.paypal.android.sdk.payments.PayPalPayment;
import com.paypal.android.sdk.payments.PayPalService;
import com.paypal.android.sdk.payments.PaymentActivity;
import com.paypal.android.sdk.payments.PaymentConfirmation;
public class MyNativeImpl extends Activity{
// private static final String TAG = "paymentdemoblog";
/**
* - Set to PaymentActivity.ENVIRONMENT_PRODUCTION to move real money.
*
* - Set to PaymentActivity.ENVIRONMENT_SANDBOX to use your test credentials
* from https://developer.paypal.com
*
* - Set to PayPalConfiguration.ENVIRONMENT_NO_NETWORK to kick the tires
* without communicating to PayPal's servers.
*/
// private static final String CONFIG_ENVIRONMENT =
// PayPalConfiguration.ENVIRONMENT_NO_NETWORK;
private static final String CONFIG_ENVIRONMENT = PayPalConfiguration.ENVIRONMENT_SANDBOX;
// note that these credentials will differ between live & sandbox
// environments.
private static final String CONFIG_CLIENT_ID = "Aeqc2X1rBIEUtDNqsaRNr0h1neFo9QnNmfgmpA3D32uSLaHpGJu9NV1KfMnFmy7O-_hV47I7ST0SXDW2";
private static final int REQUEST_CODE_PAYMENT = 1;
private static final int REQUEST_CODE_FUTURE_PAYMENT = 2;
private static PayPalConfiguration config = new PayPalConfiguration()
.environment(CONFIG_ENVIRONMENT)
.clientId(CONFIG_CLIENT_ID)
// The following are only used in PayPalFuturePaymentActivity.
.merchantName("Hipster Store")
.merchantPrivacyPolicyUri(
Uri.parse("https://www.example.com/privacy"))
.merchantUserAgreementUri(
Uri.parse("https://www.example.com/legal"));
PayPalPayment thingToBuy;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = new Intent(this, PayPalService.class);
intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
startService(intent);
findViewById(R.id.order).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
thingToBuy = new PayPalPayment(new BigDecimal("10"), "USD",
"HeadSet", PayPalPayment.PAYMENT_INTENT_SALE);
Intent intent = new Intent(MyNativeImpl.this,
PaymentActivity.class);
intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);
startActivityForResult(intent, REQUEST_CODE_PAYMENT);
}
});
}
public void onFuturePaymentPressed(View pressed) {
Intent intent = new Intent(MyNativeImpl.this,
PayPalFuturePaymentActivity.class);
startActivityForResult(intent, REQUEST_CODE_FUTURE_PAYMENT);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_PAYMENT) {
if (resultCode == Activity.RESULT_OK) {
PaymentConfirmation confirm = data
.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
if (confirm != null) {
try {
System.out.println(confirm.toJSONObject().toString(4));
System.out.println(confirm.getPayment().toJSONObject()
.toString(4));
Toast.makeText(getApplicationContext(), "Order placed",
Toast.LENGTH_LONG).show();
} catch (Exception e) {
e.printStackTrace();
}
}
} else if (resultCode == Activity.RESULT_CANCELED) {
System.out.println("The user canceled.");
} else if (resultCode == PaymentActivity.RESULT_EXTRAS_INVALID) {
System.out
.println("An invalid Payment or PayPalConfiguration was submitted. Please see the docs.");
}
} else if (requestCode == REQUEST_CODE_FUTURE_PAYMENT) {
if (resultCode == Activity.RESULT_OK) {
PayPalAuthorization auth = data
.getParcelableExtra(PayPalFuturePaymentActivity.EXTRA_RESULT_AUTHORIZATION);
if (auth != null) {
try {
Log.i("FuturePaymentExample", auth.toJSONObject()
.toString(4));
String authorization_code = auth.getAuthorizationCode();
Log.i("FuturePaymentExample", authorization_code);
sendAuthorizationToServer(auth);
Toast.makeText(getApplicationContext(),
"Future Payment code received from PayPal",
Toast.LENGTH_LONG).show();
} catch (Exception e) {
Log.e("FuturePaymentExample",
"an extremely unlikely failure occurred: ", e);
e.printStackTrace();
}
}
} else if (resultCode == Activity.RESULT_CANCELED) {
Log.i("FuturePaymentExample", "The user canceled.");
} else if (resultCode == PayPalFuturePaymentActivity.RESULT_EXTRAS_INVALID) {
Log.i("FuturePaymentExample",
"Probably the attempt to previously start the PayPalService had an invalid PayPalConfiguration. Please see the docs.");
}
}
}
private void sendAuthorizationToServer(PayPalAuthorization authorization) {
}
public void onFuturePaymentPurchasePressed(View pressed) {
// Get the Application Correlation ID from the SDK
String correlationId = PayPalConfiguration
.getApplicationCorrelationId(this);
Log.i("FuturePaymentExample", "Application Correlation ID: "
+ correlationId);
// TODO: Send correlationId and transaction details to your server for
// processing with
// PayPal...
Toast.makeText(getApplicationContext(),
"App Correlation ID received from SDK", Toast.LENGTH_LONG)
.show();
}
#Override
public void onDestroy() {
// Stop service when done
stopService(new Intent(this, PayPalService.class));
super.onDestroy();
}
public boolean isSupported() {
return true;
}
}
Now I am getting exception during android build:
All input files are considered out-of-date for incremental task
':compileDebugJavaWithJavac'. Compiling with source level 1.7 and
target level 1.7. :compileDebugJavaWithJavac - is not incremental
(e.g. outputs have changed, no previous execution, etc.). file or
directory
'/tmp/build220258639476712910xxx/MyApplication/src/debug/java', not
found Compiling with JDK Java compiler API.
/tmp/build220258639476712910xxx/MyApplication/src/main/java/com/mycompany/myapp/MyNativeImpl.java:62:
error: cannot find symbol setContentView(R.layout.activity_main);
^ symbol: variable activity_main location: class layout
/tmp/build220258639476712910xxx/MyApplication/src/main/java/com/mycompany/myapp/MyNativeImpl.java:74:
error: cannot find symbol
Intent intent = new Intent(MainActivity.this,
^ symbol: class MainActivity /tmp/build220258639476712910xxx/MyApplication/src/main/java/com/mycompany/myapp/MyNativeImpl.java:67:
error: cannot find symbol
findViewById(R.id.order).setOnClickListener(new OnClickListener() {
^ symbol: variable order location: class id /tmp/build220258639476712910xxx/MyApplication/src/main/java/com/mycompany/myapp/MyNativeImpl.java:86:
error: cannot find symbol Intent intent = new
Intent(MainActivity.this,
^ symbol: class MainActivity location: class MyNativeImpl Note: Some input files use or override a
deprecated API. Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations. Note:
Recompile with -Xlint:unchecked for details. 4 errors
:compileDebugJavaWithJavac FAILED :compileDebugJavaWithJavac
(Thread[Daemon worker,5,main]) completed. Took 10.51 secs.
FAILURE: Build failed with an exception.
Can anyone please help....

There is no activity_main in the XML bundle which is why the auto-generated R class from Android can't find it.
I also noticed you inherited Activity in the impl class which is wrong you should create a separate activity class assuming that's actually what you want to do (you might need to interface with the core Codename One activity).
Since I'm unfamiliar with the PayPal integration I'm guessing that activity_main refers to your own activity which is really the CodenameOneActivity. In that sense most of that code is redundant as we already generate that, you just need to bind the calls into the paypal native code.

Related

How can i get the output as just the city name instead of whole address in my App when using Google API?

Even when the user search for any locality in a city, the output should be name of the city.
package com.example.rajat.location;
import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.view.View; import android.widget.TextView;
import com.google.android.gms.common.GooglePlayServicesNotAvailableException; import com.google.android.gms.common.GooglePlayServicesRepairableException; import com.google.android.gms.common.api.Status; import com.google.android.gms.location.places.Place; import com.google.android.gms.location.places.ui.PlaceAutocomplete;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
/*
* In this method, Start PlaceAutocomplete activity
* PlaceAutocomplete activity provides--
* a search box to search Google places
*/
public void findPlace(View view) {
try {
Intent intent =
new PlaceAutocomplete
.IntentBuilder(PlaceAutocomplete.MODE_FULLSCREEN)
.build(this);
startActivityForResult(intent, 1);
} catch (GooglePlayServicesRepairableException e) {
// TODO: Handle the error.
} catch (GooglePlayServicesNotAvailableException e) {
// TODO: Handle the error.
}
}
// A place has been received; use requestCode to track the request.
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1) {
if (resultCode == RESULT_OK) {
// retrive the data by using getPlace() method.
Place place = PlaceAutocomplete().getPlace(this, data);
Log.e("Tag", "Place: " + place.getAddress() + place.getPhoneNumber());
((TextView) findViewById(R.id.searched_address))
.setText(place.getName()+",\n"+
place.getAddress() +"\n" + place.getPhoneNumber());
} else if (resultCode == PlaceAutocomplete.RESULT_ERROR) {
Status status = PlaceAutocomplete.getStatus(this, data);
// TODO: Handle the error.
Log.e("Tag", status.getStatusMessage());
} else if (resultCode == RESULT_CANCELED) {
// The user canceled the operation.
}
}
} }
You need to use a key specific to the Google Places API to retrieve the city name from your JSON response object.
This link shows the JSON response you are getting back (the key value pairs)
https://developers.google.com/places/web-service/details
Inspect your JSON response object (which i believe is your "Place" object).
Run a debug statement on this line of code. Place place = PlaceAutocomplete().getPlace(this, data);
Once you know the key for City, grab the City value and only populate your UI with the City value.

app unfortunately stopped form codenameone with paypal integration

Written the below code in native interface implemented class:
package com.mycompany.myapp;
import com.paypal.android.sdk.payments.PayPalAuthorization;
import com.paypal.android.sdk.payments.PayPalConfiguration;
import com.paypal.android.sdk.payments.PayPalFuturePaymentActivity;
import com.paypal.android.sdk.payments.PayPalPayment;
import com.paypal.android.sdk.payments.PayPalService;
import com.paypal.android.sdk.payments.PaymentActivity;
import com.paypal.android.sdk.payments.PaymentConfirmation;
import android.content.Intent;
import android.net.Uri;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.R;
import android.widget.Toast;
import android.*;
import android.widget.Toast;
import com.codename1.impl.android.IntentResultListener;
import com.codename1.impl.android.AndroidNativeUtil;
import com.codename1.impl.android.CodenameOneActivity;
//import com.codename1.impl.android.LifecycleListener;
//import com.codename1.impl.android.OnInitListener;
import java.math.BigDecimal;
public class MyNativeImpl{
// private static final String TAG = "paymentdemoblog";
/**
* - Set to PaymentActivity.ENVIRONMENT_PRODUCTION to move real money.
*
* - Set to PaymentActivity.ENVIRONMENT_SANDBOX to use your test credentials
* from https://developer.paypal.com
*
* - Set to PayPalConfiguration.ENVIRONMENT_NO_NETWORK to kick the tires
* without communicating to PayPal's servers.
*/
// private static final String CONFIG_ENVIRONMENT =
// PayPalConfiguration.ENVIRONMENT_NO_NETWORK;
private static final String CONFIG_ENVIRONMENT = PayPalConfiguration.ENVIRONMENT_SANDBOX;
// note that these credentials will differ between live & sandbox
// environments.
private static final String CONFIG_CLIENT_ID = "Aeqc2X1rBIEUtDNqsaRNr0h1neFo9QnNmfgmpA3D32uSLaHpGJu9NV1KfMnFmy7O-_hV47I7ST0SXDW2";
private static final int REQUEST_CODE_PAYMENT = 1;
private static final int REQUEST_CODE_FUTURE_PAYMENT = 2;
private static PayPalConfiguration config = new PayPalConfiguration()
.environment(CONFIG_ENVIRONMENT)
.clientId(CONFIG_CLIENT_ID)
// The following are only used in PayPalFuturePaymentActivity.
.merchantName("Hipster Store")
.merchantPrivacyPolicyUri(
Uri.parse("https://www.example.com/privacy"))
.merchantUserAgreementUri(
Uri.parse("https://www.example.com/legal"));
PayPalPayment thingToBuy;
private static Activity activity() {
return com.codename1.impl.android.AndroidNativeUtil.getActivity();
}
public String payPalTest() {
AndroidNativeUtil.getActivity().runOnUiThread(new Runnable() {
public void run() {
Intent intent = new Intent(activity(), PayPalService.class);
intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
activity().startService(intent);
}
});
AndroidNativeUtil.getActivity().runOnUiThread(new Runnable() {
public void run() {
thingToBuy = new PayPalPayment(new BigDecimal("10"), "USD",
"HeadSet", PayPalPayment.PAYMENT_INTENT_SALE);
Intent intent = new Intent(activity(),
PaymentActivity.class);
intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);
activity().startActivityForResult(intent, REQUEST_CODE_PAYMENT);
AndroidNativeUtil.startActivityForResult(intent, new IntentResultListener(){
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_PAYMENT) {
if (resultCode == Activity.RESULT_OK) {
PaymentConfirmation confirm = data
.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
if (confirm != null) {
try {
System.out.println(confirm.toString());
System.out.println(confirm.toString());
Toast.makeText(activity(), "Order placed",
Toast.LENGTH_LONG).show();
} catch (Exception e) {
e.printStackTrace();
}
}
} else if (resultCode == Activity.RESULT_CANCELED) {
System.out.println("The user canceled.");
} else if (resultCode == PaymentActivity.RESULT_EXTRAS_INVALID) {
System.out
.println("An invalid Payment or PayPalConfiguration was submitted. Please see the docs.");
}
} else if (requestCode == REQUEST_CODE_FUTURE_PAYMENT) {
if (resultCode == Activity.RESULT_OK) {
PayPalAuthorization auth = data
.getParcelableExtra(PayPalFuturePaymentActivity.EXTRA_RESULT_AUTHORIZATION);
if (auth != null) {
try {
String authorization_code = auth.getAuthorizationCode();
Log.i("FuturePaymentExample", authorization_code);
sendAuthorizationToServer(auth);
Toast.makeText(activity(),
"Future Payment code received from PayPal",
Toast.LENGTH_LONG).show();
} catch (Exception e) {
Log.e("FuturePaymentExample",
"an extremely unlikely failure occurred: ", e);
e.printStackTrace();
}
}
} else if (resultCode == Activity.RESULT_CANCELED) {
Log.i("FuturePaymentExample", "The user canceled.");
} else if (resultCode == PayPalFuturePaymentActivity.RESULT_EXTRAS_INVALID) {
Log.i("FuturePaymentExample",
"Probably the attempt to previously start the PayPalService had an invalid PayPalConfiguration. Please see the docs.");
}
}
}
});
}
});
// thingToBuy = new PayPalPayment(new BigDecimal("10"), "USD",
// "HeadSet", PayPalPayment.PAYMENT_INTENT_SALE);
//
// Intent intent = new Intent(activity(),PaymentActivity.class);
//
// intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);
// activity().startActivityForResult(intent, REQUEST_CODE_PAYMENT);
//Intent intent=new Intent(Intent.ACTION_VIEW);
//intent.setData(Uri.parse("http://www.javatpoint.com"));
//activity().startActivity(intent);
return "test";
}
private void sendAuthorizationToServer(PayPalAuthorization authorization) {
}
public void onDestroy() {
}
public boolean isSupported() {
return false;
}
}
call from main class:
MyNative my = (MyNative)NativeLookup.create(MyNative.class);
if(my!= null){
String aa =my.payPalTest();
System.out.println("result::" + aa);
System.out.println("paypalInt" + my.toString());
}
The code build succesfully but when I have tried to access it from android mobile,it gives error:
Unfortunately has stopped.How to resolve the problem
That means you have an uncaught exception, connect your device with cable and open android ddms to see the trace and log

Google Play In-app billing V3 - Error - Authentication is Required

I have looked at other similar questions on SO regarding the same issue and all point to the same point. To check the ID of the product. I am implementing in-app purchases for the first time and i think i am using the correct product id in the code. I am following TrivialDrive sample.
So, the error is as follows:
My product id from Google Play:
My code is as follows:
package com.xx.xxx;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.xx.xxx.util.IabHelper;
import com.xx.xxx.util.IabResult;
import com.xx.xxx.util.Inventory;
import com.xx.xxx.util.Purchase;
public class UpgradeDonateActivity extends AppCompatActivity {
private String base64EncodedPublicKey = "PUBLIC_KEY_REPLACED";
private static final int PURCHASE_RESPONSE = 1;
private static final String PURCHASE_TOKEN = "purchase_token";
private static final String SKU_UPGRADE_2 = "test";
//private static final String SKU_UPGRADE = "Upgrade";
private static final String SKU_DONATE_10 = "donate_10";
private static final String SKU_DONATE_5 = "donate_5";
private static final String SKU_DONATE_3 = "donate_3";
private static final String SKU_DONATE_2 = "donate_2";
private boolean mIsUpgraded = false;
private Toolbar toolbar;
private TextView title;
private IabHelper mIabHelper;
private Button btnUpgrade;
IabHelper.QueryInventoryFinishedListener mGotInventoryListener
= new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result,
Inventory inventory) {
Log.d(Const.DEBUG, "Query inventory finished");
if (mIabHelper == null) return;
if (result.isFailure()) {
// Handle failure
Toast.makeText(UpgradeDonateActivity.this, "onQueryInventoryFinished Failed", Toast.LENGTH_LONG).show();
return;
}
Log.d(Const.DEBUG, "Query inventory successful");
Purchase upgradePurchase = inventory.getPurchase(SKU_UPGRADE_2);
mIsUpgraded = (upgradePurchase != null && verifyDeveloperPayload(upgradePurchase));
Log.d(Const.DEBUG, "User is " + (mIsUpgraded ? "Upgraded" : "Not Upgraded"));
}
};
boolean verifyDeveloperPayload(Purchase p) {
String payload = p.getDeveloperPayload();
return true;
}
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener
= new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result,
Purchase purchase) {
Log.d(Const.DEBUG, "Purchase finished: " + result + ", purchase: " + purchase);
if(mIabHelper == null) return;
if (result.isFailure()) {
// Handle error
Log.d(Const.DEBUG, "Error Purchasing: "+result);
return;
}
if(!verifyDeveloperPayload(purchase)) {
Log.d(Const.DEBUG, "Error purchasing. Authenticity verification failed.");
return;
}
Log.d(Const.DEBUG, "Purchase successful.");
if(purchase.getSku().equals(SKU_UPGRADE_2)) {
Log.d(Const.DEBUG, "Purchase is upgrade. Congratulating user.");
mIsUpgraded = true;
}
}
};
IabHelper.OnConsumeFinishedListener mConsumeFinishedListener =
new IabHelper.OnConsumeFinishedListener() {
public void onConsumeFinished(Purchase purchase,
IabResult result) {
if (result.isSuccess()) {
//clickButton.setEnabled(true);
Toast.makeText(UpgradeDonateActivity.this, "", Toast.LENGTH_LONG).show();
} else {
// handle error
Toast.makeText(UpgradeDonateActivity.this, "Error", Toast.LENGTH_LONG).show();
}
}
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_upgrade_donate);
toolbar = (Toolbar) findViewById(R.id.toolbar);
title = (TextView) toolbar.findViewById(R.id.toolbar_title);
title.setText("");
setSupportActionBar(toolbar);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
btnUpgrade = (Button) findViewById(R.id.button_upgrade);
btnUpgrade.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mIabHelper = new IabHelper(UpgradeDonateActivity.this, base64EncodedPublicKey);
mIabHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
#Override
public void onIabSetupFinished(IabResult result) {
if (!result.isSuccess()) {
Log.d(Const.DEBUG, "In-app Billing setup Failed");
} else {
Log.d(Const.DEBUG, "In-app Billing setup OK");
Toast.makeText(UpgradeDonateActivity.this, "In-app Billing setup OK", Toast.LENGTH_SHORT).show();
mIabHelper.launchPurchaseFlow(UpgradeDonateActivity.this, SKU_UPGRADE_2, PURCHASE_RESPONSE, mPurchaseFinishedListener, PURCHASE_TOKEN);
}
}
});
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d(Const.DEBUG, "onActivityResult(" + requestCode + "," + resultCode + "," + data);
if (mIabHelper == null) return;
// Pass on the activity result to the helper for handling
if (!mIabHelper.handleActivityResult(requestCode, resultCode, data)) {
// not handled, so handle it ourselves (here's where you'd
// perform any handling of activity results not related to in-app
// billing...
super.onActivityResult(requestCode, resultCode, data);
} else {
Log.d(Const.DEBUG, "onActivityResult handled by IABUtil.");
}
}
public void consumeItem() {
mIabHelper.queryInventoryAsync(mGotInventoryListener);
}
#Override
public void onDestroy() {
super.onDestroy();
if (mIabHelper != null) mIabHelper.dispose();
mIabHelper = null;
}
}
Can anyone tell me what is it that i am doing wrong in this case? How should i fix it?
Make sure your .apk with billing in place (and right permissions) is Published (be it alpha) and allow some time for Google Play to absorb the new .apk, may be a couple of hours.
Also, make sure the application version code in your current development build is the same as the one of the published billing-enabled build.
On upload APK page in ALPHA TESTING there is a link "Opt-in URL ". Go there and accept being a tester using the testing account.
Aso, here is a useful checklist https://stackoverflow.com/a/22469253/1819570

PayPal Android SDK keeps on "checking my device"

I am trying to use the PayPal Android SDK (https://github.com/paypal/PayPal-Android-SDK) in my App. I used the same methods like their example. All parameters like ClientID are the correct ones from my PayPal sandbox. When I press the button that calls the PayPal activity, a screen captioned "Checking this device...", a spinning ProgressBar and a PayPal Logo appears on the screen. I let this screen like this for hours, but nothing happend.
Thanks for help and excuse me for my bad english, it's my first question here and I am from Germany...
There is now output in LogCat From PayPal or its Activity. Here is my code:
package de.jimpachnet.xaver;
import java.math.BigDecimal;
import org.json.JSONException;
import com.paypal.android.sdk.payments.PayPalPayment;
import com.paypal.android.sdk.payments.PayPalService;
import com.paypal.android.sdk.payments.PaymentActivity;
import com.paypal.android.sdk.payments.PaymentConfirmation;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
public class Premium extends Activity {
private static final String CONFIG_ENVIRONMENT = PaymentActivity.ENVIRONMENT_NO_NETWORK;
// note that these credentials will differ between live & sandbox environments.
private static final String CONFIG_CLIENT_ID = "XXXXXXXXXXXX";
// when testing in sandbox, this is likely the -facilitator email address.
private static final String CONFIG_RECEIVER_EMAIL = "XXXXXXXXX-facilitator#t-online.de";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_premium);
Intent intent = new Intent(this, PayPalService.class);
intent.putExtra(PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT, CONFIG_ENVIRONMENT);
intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, CONFIG_CLIENT_ID);
intent.putExtra(PaymentActivity.EXTRA_RECEIVER_EMAIL, CONFIG_RECEIVER_EMAIL);
startService(intent);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.premium, menu);
return true;
}
public void onButtonPayPal (View view) {
onBuyPressed();
}
public void onBuyPressed() {
PayPalPayment thingToBuy = new PayPalPayment(new BigDecimal("2.11"), "USD", "StXaverAppPremiumAccount");
Intent intent = new Intent(this, PaymentActivity.class);
intent.putExtra(PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT, CONFIG_ENVIRONMENT);
intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, CONFIG_CLIENT_ID);
intent.putExtra(PaymentActivity.EXTRA_RECEIVER_EMAIL, CONFIG_RECEIVER_EMAIL);
intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, CONFIG_CLIENT_ID);
intent.putExtra(PaymentActivity.EXTRA_PAYER_ID, "test");
intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);
startActivityForResult(intent, 0);
}
#Override
protected void onActivityResult (int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
PaymentConfirmation confirm = data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
if (confirm != null) {
try {
Log.i("paymentExample", confirm.toJSONObject().toString(4));
} catch (JSONException e) {
Log.e("paymentExample", "an extremely unlikely failure occurred: ", e);
}
}
}
else if (resultCode == Activity.RESULT_CANCELED) {
Log.i("paymentExample", "Nope");
}
else if (resultCode == PaymentActivity.RESULT_PAYMENT_INVALID) {
Log.i("paymentExample", "An invalid payment was submitted. Please see the docs.");
}
}
#Override
public void onDestroy() {
stopService(new Intent(this, PayPalService.class));
super.onDestroy();
}
}

Sending tweets using Android

I want to send a tweet from Android.I have executed the following code.But I am not bale to send any tweets.Avtually the button I created is not working.Can anybody tel me wats the prob?
This is my code..
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.os.Bundle;
public class TwidgitPublicIntent extends Activity implements OnClickListener {
private static final int TWIDGIT_REQUEST_CODE = 2564;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
((Button)findViewById(R.id.tweet_button)).setOnClickListener(this);
((Button)findViewById(R.id.mention_button)).setOnClickListener(this);
((Button)findViewById(R.id.retweet_button)).setOnClickListener(this);
((Button)findViewById(R.id.message_button)).setOnClickListener(this);
}
public void onClick(View v) {
switch(v.getId()) {
case R.id.tweet_button:
// Standard tweet
Intent tIntent = new Intent("com.disretrospect.twidgit.TWEET");
tIntent.putExtra("com.disretrospect.twidgit.extras.MESSAGE", "_message_in_here_");
try {
this.startActivityForResult(tIntent, TWIDGIT_REQUEST_CODE);
} catch (ActivityNotFoundException e) {
// If Twidgit is not installed
}
break;
case R.id.mention_button:
// Mention
Intent mIntent = new Intent("com.disretrospect.twidgit.MENTION");
mIntent.putExtra("com.disretrospect.twidgit.extras.TO", "_username_to_xmention_");
mIntent.putExtra("com.disretrospect.twidgit.extras.MESSAGE", "_message_in_here_");
try {
this.startActivityForResult(mIntent, TWIDGIT_REQUEST_CODE);
} catch (ActivityNotFoundException e) {
// If Twidgit is not installed
}
break;
case R.id.retweet_button:
// Retweet a tweet
Intent rtIntent = new Intent("com.disretrospect.twidgit.RETWEET");
rtIntent.putExtra("com.disretrospect.twidgit.extras.MESSAGE", "_message_in_here_");
rtIntent.putExtra("com.disretrospect.twidgit.extras.VIA", "_original_author_of_tweet_name_");
try {
this.startActivityForResult(rtIntent, TWIDGIT_REQUEST_CODE);
} catch (ActivityNotFoundException e) {
// If Twidgit is not installed
}
break;
case R.id.message_button:
// Send DM
Intent dmIntent = new Intent("com.disretrospect.twidgit.DIRECT_MESSAGE");
dmIntent.putExtra("com.disretrospect.twidgit.extras.TO", "_username_to_send_dm_to_");
dmIntent.putExtra("com.disretrospect.twidgit.extras.MESSAGE", "_message_in_here_");
try {
this.startActivityForResult(dmIntent, TWIDGIT_REQUEST_CODE);
} catch (ActivityNotFoundException e) {
// If Twidgit is not installed
}
break;
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Check result code
if(resultCode == Activity.RESULT_OK) {
// Check requestCode
switch(requestCode) {
case TWIDGIT_REQUEST_CODE:
// Handle successful return
break;
}
} else if(resultCode == Activity.RESULT_CANCELED){
// Handle canceled activity
}
}
}
I'm not able to edit your post so i have to put this in an answer: could you provide more details about the problem? More precisely, what do you mean by "the button is not working?" Is anything happening when you click the button, or not? If nothing happens, might be that you run into the ActivityNotFoundException. Since it is catched, but no action is taken, it's transparent. Have you tried debugging, with a break point on the onClick method?

Categories

Resources