SHARE
TWEET

register app bug

y_c Mar 14th, 2017 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class MyReceiver extends BroadcastReceiver {
  2.  
  3.     @Override
  4.     public void onReceive(Context context, Intent intent) {
  5.  
  6.         if (intent == null || intent.getAction() == null)
  7.             return;
  8.         String action = intent.getAction();
  9.         if (action.equals("com.clover.intent.action.LINE_ITEM_ADDED")) {
  10.  
  11.             String orderId = intent.getStringExtra("com.clover.intent.extra.ORDER_ID");
  12.             String lineItemId = intent.getStringExtra("com.clover.intent.extra.LINE_ITEM_ID");
  13.             String itemId = intent.getStringExtra("com.clover.intent.extra.ITEM_ID");
  14.  
  15.             Log.d(MyReceiver.class.getName(), "orderId: " + orderId);
  16.             Log.d(MyReceiver.class.getName(), "lineItemId: " + lineItemId);
  17.             Log.d(MyReceiver.class.getName(), "itemId: " + itemId);
  18.  
  19.             Intent intent = new Intent(context, NewService.class);
  20.             intent.putExtra("com.clover.intent.extra.ORDER_ID", orderId);
  21.             context.startService(intent);
  22.         }
  23.     }
  24. }
  25.  
  26. public class NewService extends IntentService {
  27.  
  28.     private String orderId;
  29.     private OrderConnector orderConnector;
  30.     private static final String TAG = NewService.class.getName();
  31.  
  32.     public NewService() {
  33.         super("newService");
  34.     }
  35.  
  36.     @Override
  37.     public void onCreate() {
  38.         super.onCreate();
  39.         if (!connect())
  40.             stopSelf();
  41.     }
  42.  
  43.     private boolean connect() {
  44.         Account mAccount = CloverAccount.getAccount(this);
  45.         if (mAccount == null)
  46.             return false;
  47.  
  48.         orderConnector = new OrderConnector(this, mAccount, null);
  49.         orderConnector.connect();
  50.         return true;
  51.     }
  52.  
  53.     @Override
  54.     protected void onHandleIntent(Intent intent) {
  55.         try {
  56.  
  57.             orderId = intent.getStringExtra("com.clover.intent.extra.ORDER_ID");
  58.             if (orderId == null) return;
  59.  
  60.             List<LineItem> lineItems = orderConnector.getOrder(orderId).getLineItems();
  61.             if (lineItems == null || lineItems.isEmpty()) return;
  62.  
  63.             for (LineItem line : lineItems) {
  64.                 Log.d(TAG, "lineItem ID: " + line.getId());
  65.                 if (line.isNotNullItem())
  66.                     Log.d(TAG, "item ID: " + line.getItem().getId());
  67.                 else
  68.                     Log.d(TAG, "item null ");
  69.             }
  70.         } catch (Exception e) {
  71.             e.printStackTrace();
  72.         }
  73.     }
  74.  
  75.     @Override
  76.     public void onDestroy() {
  77.         super.onDestroy();
  78.         if (orderConnector != null) {
  79.             orderConnector.disconnect();
  80.             orderConnector = null;
  81.         }
  82.     }
  83. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top