2016-11-24 5 views
3

私は "FORT" SDKを使用した私のアプリで支払いを統合したいと思います。私は "payfort.com"ウェブサイトのドキュメントに従ったが、私がライブラリを統合すると、私のアプリがクラッシュした。たManifest.xmlでアンドロイドのFORT SDKの統合

E/AndroidRuntime: FATAL EXCEPTION: main 
                    Process: com.newsolution.jiibli, PID: 12133 
                    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.newsolution.jiibli/com.payfort.fort.android.sdk.activities.InitSecureConnectionActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 
                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3253) 
                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349) 
                     at android.app.ActivityThread.access$1100(ActivityThread.java:223) 
                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794) 
                     at android.os.Handler.dispatchMessage(Handler.java:102) 
                     at android.os.Looper.loop(Looper.java:148) 
                     at android.app.ActivityThread.main(ActivityThread.java:7223) 
                     at java.lang.reflect.Method.invoke(Native Method) 
                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
                    Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 
                     at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:343) 
                     at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:312) 
                     at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:277) 
                     at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
                     at com.payfort.fort.android.sdk.activities.InitSecureConnectionActivity.onCreate(InitSecureConnectionActivity.java:50) 
                     at android.app.Activity.performCreate(Activity.java:6877) 
                     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1136) 
                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206) 
                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)  
                     at android.app.ActivityThread.access$1100(ActivityThread.java:223)  
                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)  
                     at android.os.Handler.dispatchMessage(Handler.java:102)  
                     at android.os.Looper.loop(Looper.java:148)  
                     at android.app.ActivityThread.main(ActivityThread.java:7223)  
                     at java.lang.reflect.Method.invoke(Native Method)  
                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)  
                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)  
+0

でオーバライドマニフェストを使用して、あなたの活動はAppCompatActivity' 'から延びているのでしょうか? –

+0

いいえ、アクティビティ –

+0

から拡張しています。私はそれをAppCompatActivityから拡張するように変更しましたが、新しいアプリケーションでsdkを使用したときと同じ問題を抱えていますが、現行のアプリケーションではありません。 –

答えて

0

この

は、エラー出力され、私はスタイルがGradleのインポートにAppCompactTheme

  <activity android:name=".Activity.PaymentMethod" 
      android:theme="@style/AppTheme"/> 

から

compile project(':FORTSDKv1.2') 

は私が開始ライブラリを拡張します結果に対するインテントを伴うPaymentMethodアクティビティ: コールメソッドpay();

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    activity = this; 
    setContentView(R.layout.activity_payment_method); 
    fortCallback = FortCallback.Factory.create(); 
    pay(); 
    } 
    public void pay() { 
    try { 
     ProviderInstaller.installIfNeeded(getApplicationContext()); 
    } catch (GooglePlayServicesRepairableException e) { 
     e.printStackTrace(); 
    } catch (GooglePlayServicesNotAvailableException e) { 
     e.printStackTrace(); 
    } 
    new sdkToken().execute();// get SDK Token and pass it to paid method 
} 

class sdkToken extends AsyncTask<String, Void, String> { 
    public sdkToken() { 
    } 

    protected void onPreExecute() { 
     super.onPreExecute(); 
    } 

    protected String doInBackground(String... params) { 
     signature = getSignature(); 
     String jsonRequestString = "{\"access_code\" : \""+access_code+"\" " + 
       ", \"service_command\" : \"SDK_TOKEN\", \"language\" : \"en\"," 
       + "\"merchant_identifier\" : \""+merchant_identifier+"\", \"signature\" : \"" + signature + "\", " 
       + "\"device_id\" : \"" + FortSdk.getDeviceId(PaymentMethod.this) + "\"}"; 

     HttpParams httpParameters = new BasicHttpParams(); 
     // Set the timeout in milliseconds until a connection is established. 
     int timeoutConnection = 10000; 
     HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); 
     // Set the default socket timeout (SO_TIMEOUT) 
     // in milliseconds which is the timeout for waiting for data. 
     int timeoutSocket = 10000; 
     HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); 

     // Instantiate the custom HttpClient 
     HttpClient httpclient = new MyHttpClient(httpParameters, getApplicationContext()); 
     // DefaultHttpClient httpclient =new DefaultHttpClient(); 
     HttpPost request = new HttpPost("https://sbpaymentservices.payfort.com/FortAPI/paymentApi"); 
     StringEntity param = null; 
     try { 
      param = new StringEntity(jsonRequestString);// Setup Http POST entity with JSON String 
      // Setup request type as JSON 
      request.addHeader("content-type", "application/json"); 
      request.setEntity(param); 
      HttpResponse response = null; 
      response = httpclient.execute(request); // Post request to FORT 
      sb = new StringBuilder(); // Read response using StringBuilder 
      BufferedReader reader = null; 
      reader = new BufferedReader(new InputStreamReader(
        response.getEntity().getContent()), 65728); 
      String line = null; 
      while ((line = reader.readLine()) != null) { 
       sb.append(line); 
      } 
     } catch (Exception e) { 
      e.printStackTrace(); 
      return null; 
     } 
     return "" + sb.toString(); 
    } 

    protected void onPostExecute(String fortResponse) { 
     super.onPostExecute(fortResponse); 
     if (fortResponse != null) { 
      JSONObject jsonObject = null; 
      System.out.println(sb.toString()); 
      try { 
       jsonObject = new JSONObject(fortResponse); 
       sdk_token = jsonObject.getString("sdk_token"); 
       System.out.println(sdk_token); 
       progressBar.setVisibility(View.GONE); 
       paid(sdk_token); 
      } catch (JSONException e) { 
       e.printStackTrace(); 
      } 
     } else { 
      progressBar.setVisibility(View.GONE); 
      Log.i("fortResponse", " fortResponse==null"); 
      Toast.makeText(activity, getString(R.string.compatible), Toast.LENGTH_LONG).show(); 
     } 
    } 
} 

private void paid(String sdk_token) { 
    fortRequest = new FortRequest(); 
    Map<String, String> requestMap = new HashMap<>(); 
    requestMap.put("merchant_reference", random()); 
    requestMap.put("language", "en"); 
    requestMap.put("order_description", "android"); 
    requestMap.put("currency", "SAR"); 
    requestMap.put("amount", "100"); 
    requestMap.put("command", "AUTHORIZATION");//PURCHASE 
    requestMap.put("customer_name", "add any name"); 
    requestMap.put("eci", "ECOMMERCE"); 
    requestMap.put("customer_email", "add email"); 
    requestMap.put("sdk_token", sdk_token); 
    fortRequest.setShowResponsePage(true); 
    fortRequest.setRequestMap(requestMap); 
    try { 
     FortSdk.getInstance().registerCallback(this, fortRequest, FortSdk.ENVIRONMENT.TEST, 5, fortCallback, 
       new FortInterfaces.OnTnxProcessed() { 
        @Override 
        public void onCancel(Map<String, String> requestParamsMap, Map<String, 
          String> responseMap) { 
         //TODO: handle me 
         JSONObject responseObject = new JSONObject(responseMap); 
         try { 
          String response_message = responseObject.getString("response_message"); 
          paymentType = 0; 
          Toast.makeText(PaymentMethod.this, "" + response_message, Toast.LENGTH_LONG).show(); 
         } catch (JSONException e) { 
          e.printStackTrace(); 
         } 
        } 

        @Override 
        public void onSuccess(Map<String, String> requestParamsMap, Map<String, 
          String> fortResponseMap) { 
         System.out.println("success requestParamsMap " + requestParamsMap); 
         System.out.println("success fortResponseMap " + fortResponseMap); 
         JSONObject responseObject = new JSONObject(fortResponseMap); 
         try { 
          String response_message = responseObject.getString("response_message"); 
          Toast.makeText(PaymentMethod.this, "" + response_message, Toast.LENGTH_LONG).show(); 
          Intent intent = new Intent(); 
          intent.putExtra("cardNo", cardNo); 
          intent.putExtra("cardId", cardId); 
          setResult(2, intent); 
          finish(); 
         } catch (JSONException e) { 
          e.printStackTrace(); 
         } 
        } 

        @Override 
        public void onFailure(Map<String, String> requestParamsMap, Map<String, 
          String> fortResponseMap) { 
         System.out.println("requestParamsMap " + requestParamsMap); 
         System.out.println("fortResponseMap " + fortResponseMap); 
         JSONObject responseObject = new JSONObject(fortResponseMap); 
         try { 
          String response_message = responseObject.getString("response_message"); 
          Toast.makeText(PaymentMethod.this, response_message, Toast.LENGTH_LONG).show(); 
          Intent intent = new Intent(PaymentMethod.this, PayFail.class); 
          intent.putExtra("cardNo", cardNo); 
          intent.putExtra("cardType", cardType); 
          intent.putExtra("cardPersonName", cardPersonName); 
          startActivity(intent); 
         } catch (JSONException e) { 
          e.printStackTrace(); 
         } 
        } 
       }); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 

} 

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
     try { 
      fortCallback.onActivityResult(requestCode, resultCode, data); 
     } catch (Exception e) { 
      Log.i("exception", e.getMessage()); 
     } 
} 

private String getSignature() { 
    MessageDigest md = null; 
    try { 
     md = MessageDigest.getInstance("SHA-256"); 
     String text = "sadafdfeeeeaccess_code="+access_code+" 
       + "device_id=" + FortSdk.getDeviceId(PaymentMethod.this) 
       + "language=enmerchant_identifier="+merchant_identifier"+service_command=SDK_TOKENsadafdfeeee"; 
     md.update(text.getBytes("UTF-8")); // Change this to "UTF-16" if needed 

    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
    byte[] digest = md.digest(); 
    signature = String.format("%064x", new java.math.BigInteger(1, digest)); 
    return signature; 
} 

public static String random() { 
    SecureRandom secureRandom = new SecureRandom(); 
    return new BigInteger(40, secureRandom).toString(32); 
} 
0

トリックは、マニフェストファイルがpayfortのSDKと競合されている、あなたはあなたに何をしなければならなかったのは、アプリケーションタグ

+1

コードを入力してください。 –

+0

コードを入力してください。 –

+0

Theme.AppCompat.Light.NoActionBarにTheme.Transparentの親を変更します。 –

関連する問題