android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.hello/com.paypal.android.sdk.payments.PaymentActivity}; have you declared this activity in your AndroidManifest.xml?

842 views
Skip to first unread message

deep...@gmail.com

unread,
Jul 29, 2016, 7:55:22 AM7/29/16
to CodenameOne Discussions
If you are experiencing an issue please mention the full platform your issue applies to:
IDE: NetBeans/Eclipse/IDEA  : Netbeans
Desktop OS : Windows 7
Simulator : No
Device : Samsung

deep...@gmail.com

unread,
Jul 29, 2016, 7:57:33 AM7/29/16
to CodenameOne Discussions
<activity android:name="com.paypal.android.sdk.payments.LoginActivity"/>  <activity android:name="com.paypal.android.sdk.payments.PaymentMethodActivity"/>  <activity android:name="com.paypal.android.sdk.payments.PaymentConfirmActivity"/>  <activity android:name="com.paypal.android.sdk.payments.PayPalFuturePaymentActivity"/>  <activity android:name="com.paypal.android.sdk.payments.FuturePaymentConsentActivity"/>  <activity android:name="com.paypal.android.sdk.payments.FuturePaymentInfoActivity"/>  <activity android:name="io.card.payment.DataEntryActivity"/>

I have added above content from manifest file to build hint xapplication key as suggested on stack overflow but it doesn't work.

Shai Almog

unread,
Jul 30, 2016, 1:02:35 AM7/30/16
to CodenameOne Discussions
Did you package the SDK into the final APK?
What did you do besides that and what triggered that error?

deep...@gmail.com

unread,
Aug 1, 2016, 3:11:12 AM8/1/16
to CodenameOne Discussions
This is my NativeImpl code:

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.widget.Toast;
import android.*;
import android.content.Context;
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
* - 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(
.merchantUserAgreementUri(

PayPalPayment thingToBuy;
    private static Activity activity() {
        return com.codename1.impl.android.AndroidNativeUtil.getActivity();
    } 
    
     private static Context context() {
    return com.codename1.impl.android.AndroidNativeUtil.getActivity().getApplicationContext();
}   
    public String payPalTest() {
          
        
Intent intent = new Intent(activity(), PayPalService.class);
intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
activity().startService(intent);
thingToBuy = new PayPalPayment(new BigDecimal("10"), "USD",
"HeadSet", PayPalPayment.PAYMENT_INTENT_SALE);
Intent intent1 = new Intent(activity(),
PaymentActivity.class);

intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);

activity().startActivityForResult(intent1, 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(context(), "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(context(),
"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.");
}
}
        }); 

        return "test";
    }
    private void sendAuthorizationToServer(PayPalAuthorization authorization) {

}
    public void onDestroy() {
// // Stop service when done
// stopService(intent, PayPalService.class));
}
    public boolean isSupported() {
        return false;
    }

}
And i have copied PaypalSdk jar file into native directory, after this i have given android build to generate apk, what else am I supposed to do, did I miss anything?

Shai Almog

unread,
Aug 2, 2016, 12:42:52 AM8/2/16
to CodenameOne Discussions
What about the build hint specifying the additional activity? You need to inject the paypal activity into the manifest.

deep...@gmail.com

unread,
Aug 2, 2016, 2:13:07 AM8/2/16
to CodenameOne Discussions
I have injected all the activities(including main and additional activities) into manifest file and i have pasted the content of the build hints at the beginning of this post, the problem is that the build hint entries are not getting added into the manifest file of the built APK as I have decompiled the APK and checked it, so please tell me the solution for this problem.

Shai Almog

unread,
Aug 3, 2016, 1:18:21 AM8/3/16
to CodenameOne Discussions
How did you set this to the build hint. I just see XML data and not the build hint.
Did you edit the properties file directly? Are you using the GUI?

deep...@gmail.com

unread,
Aug 3, 2016, 1:44:17 AM8/3/16
to CodenameOne Discussions
I am using GUI to set the build hint, i have pasted the XML content to value part of android.xapplication key like given below :

android.xapplication= <activity android:name="com.paypal.android.sdk.payments.LoginActivity"/>  <activity android:name="com.paypal.android.sdk.payments.PaymentMethodActivity"/>  <activity android:name="com.paypal.android.sdk.payments.PaymentConfirmActivity"/>  <activity android:name="com.paypal.android.sdk.payments.PayPalFuturePaymentActivity"/>  <activity android:name="com.paypal.android.sdk.payments.FuturePaymentConsentActivity"/>  <activity android:name="com.paypal.android.sdk.payments.FuturePaymentInfoActivity"/>  <activity android:name="io.card.payment.DataEntryActivity"/>

Shai Almog

unread,
Aug 4, 2016, 12:49:48 AM8/4/16
to CodenameOne Discussions
That looks fine. Look in the codenameone_settings.properties and see that you didn't enter any spaces or special characters by mistake.

deep...@gmail.com

unread,
Aug 4, 2016, 6:06:07 AM8/4/16
to CodenameOne Discussions
That should not be an issue since I am not manipulating the content of properties file directly , Since I am operating through GUI and properties file is autogenerated there is a rare possibility of extra spaces or characters in properties file, but still i checked it from my side and i could not find any, I made another sample app and injected an activity in android.xapplication build hint, after sending the build ,i decompiled the built APK and i could not find any additional activity in the manifest file which i had injected in build hint, I am wondering if it's the right way of injecting activities or  am I doing any mistake, My colleague had posted the similiar issue on stackoverflow, there also same procedure was suggested, so pls tell me what more can be done over this? Thanks

Shai Almog

unread,
Aug 5, 2016, 2:10:35 AM8/5/16
to CodenameOne Discussions
android.xapplication should work just fine and should appear in the build hints as codename1.arg.android.xapplication. If the activity doesn't appear in the manifest that is clearly the problem but I can't see how this would happen. Can you paste your codenameone_settings.properties file?
Maybe one of the other build hints conflicts with this.

deep...@gmail.com

unread,
Aug 5, 2016, 2:39:27 AM8/5/16
to CodenameOne Discussions
This is the content of codenamone_settings.properties

#
#Thu Aug 04 11:54:32 IST 2016
codename1.arg.java.version=8
codename1.ios.appid=Q5GHSKAL2F.com.mycompany.myapp
codename1.ios.release.provision=
codename1.arg.rim.obfuscation=false
codename1.arg.ios.newStorageLocation=true
codename1.j2me.nativeTheme=nbproject/nativej2me.res
codename1.arg.ios.project_type=ios
codename1.arg.ios.interface_orientation=UIInterfaceOrientationPortrait\:UIInterfaceOrientationPortraitUpsideDown\:UIInterfaceOrientationLandscapeLeft\:UIInterfaceOrientationLandscapeRight
codename1.displayName=PayPalDemo
codename1.android.keystoreAlias=
android.gradle=true
codename1.ios.release.certificate=
codename1.android.keystorePassword=
codename1.ios.provision=
codename1.arg.android.release=true
codename1.arg.ios.dsym=false
codename1.arg.ios.statusbar_hidden=false
codename1.languageLevel=5
codename1.android.keystore=
codename1.vendor=CodenameOne
codename1.arg.win.ver=8
codename1.ios.certificatePassword=
codename1.ios.debug.certificatePassword=
codename1.mainName=MyApplication
codename1.ios.release.certificatePassword=
codename1.arg.ios.prerendered_icon=false
codename1.ios.debug.certificate=
libVersion=121
codename1.arg.android.xpermissions=<uses-permission android\:name\="android.permission.ACCESS_NETWORK_STATE"/><uses-permission android\:name\="android.permission.ACCESS_WIFI_STATE"/>
codename1.arg.ios.application_exits=false
codename1.secondaryTitle=CodenameOne_Template
codename1.description=
codename1.ios.debug.provision=
codename1.arg.j2me.nativeThemeConst=0
codename1.rim.certificatePassword=
codename1.version=1.0
codename1.ios.certificate=
codename1.arg.android.xapplication\==<activity android\:name\="com.tag.paypalblogdemo.MainActivity"/><service android\:name\="com.paypal.android.sdk.payments.PayPalService"android\:exported\="false"/><activity android\:name\="com.paypal.android.sdk.payments.PaymentActivity"/><activity android\:name\="com.paypal.android.sdk.payments.LoginActivity"/><activity android\:name\="com.paypal.android.sdk.payments.PaymentMethodActivity"/><activity android\:name\="com.paypal.android.sdk.payments.PaymentConfirmActivity"/><activity android\:name\="com.paypal.android.sdk.payments.PayPalFuturePaymentActivity"/><activity android\:name\="com.paypal.android.sdk.payments.FuturePaymentConsentActivity"/><activity android\:name\="com.paypal.android.sdk.payments.FuturePaymentInfoActivity"/><activity android\:name\="io.card.payment.DataEntryActivity"/>
codename1.icon=icon.png
codename1.rim.signtoolCsk=
codename1.arg.android.debug=false
codename1.rim.signtoolDb=
codename1.arg.ios.includePush=false
codename1.arg.ios.testFlight=false
codename1.packageName=com.mycompany.myapp

Shai Almog

unread,
Aug 5, 2016, 2:41:31 AM8/5/16
to CodenameOne Discussions
You added xapplication= instead of xapplication.

deep...@gmail.com

unread,
Aug 5, 2016, 2:47:49 AM8/5/16
to CodenameOne Discussions
Its not taking build if i don't add =, if add = it takes build

deep...@gmail.com

unread,
Aug 5, 2016, 3:04:43 AM8/5/16
to CodenameOne Discussions
Its gives following build exception if i don't put =
java.lang.RuntimeException: Cannot read packageName from /tmp/build4989325680439749120xxx/MyApplication/src/main/AndroidManifest.xml

deep...@gmail.com

unread,
Aug 5, 2016, 3:44:05 AM8/5/16
to CodenameOne Discussions
Yes that was a mistake, i corrected that mistake(removed =) and its working fine, I can see additional activity in manifest file now, thanks for your help, i really appreciate it.
Reply all
Reply to author
Forward
0 new messages