我不知道,这是否正确。但我通过在您的代码之前创建互联网连接找到了解决方案,感谢 Vikalp patel 进行识别Have you found the solution of NetworkHandler Error
。
public void PayPalButtonClick_ ( View v )
{
class asynctaskToInitLibrary extends AsyncTask<String, Integer, String >
{
@Override
protected String doInBackground(String... params)
{
URL actualUrl = null;
try
{
actualUrl = new URL("http://www.google.com") ;
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
try
{
HttpURLConnection cn = (HttpURLConnection)actualUrl.openConnection();
Log.i(cn.getResponseMessage(),"tushar:connectionResponse") ;
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
PayPal pp = PayPal.getInstance();
// If the library is already initialized, then we don't need to initialize it again.
if(pp == null)
{
// This is the main initialization call that takes in your Context, the Application ID, and the server you would like to connect to.
pp = PayPal.initWithAppID(Paypal_MPL.this, "APP-80W284485P519543T", PayPal.ENV_SANDBOX );
// -- These are required settings.
pp.setLanguage("en_US"); // Sets the language for the library.
// --
// -- These are a few of the optional settings.
// Sets the fees payer. If there are fees for the transaction, this person will pay for them. Possible values are FEEPAYER_SENDER,
// FEEPAYER_PRIMARYRECEIVER, FEEPAYER_EACHRECEIVER, and FEEPAYER_SECONDARYONLY.
pp.setFeesPayer(PayPal.FEEPAYER_EACHRECEIVER);
// Set to true if the transaction will require shipping.
pp.setShippingEnabled(true);
// Dynamic Amount Calculation allows you to set tax and shipping amounts based on the user's shipping address. Shipping must be
// enabled for Dynamic Amount Calculation. This also requires you to create a class that implements PaymentAdjuster and Serializable.
pp.setDynamicAmountCalculationEnabled(false);
// --
}
if (pp.isLibraryInitialized())
{
return "initialized" ;
}
else
{
return "not-initialized" ;
}
}
protected void onPostExecute(String result)
{
initializationStatus ( result ) ;
}
}
asynctaskToInitLibrary object = new asynctaskToInitLibrary() ;
object.execute("") ;
}