question

dipen avatar image
dipen asked dipen commented

How to call intent in Clover APP

Hi Team,

I am trying to apply the discount to order when LINEITEMADDED, but it seems like the intent is not fetching the event from clover.

Below is onReceive() method of BroadcastReceiver class which i have used to intent.

public class EventReceiver extends BroadcastReceiver {    
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (action.equals("com.clover.intent.action.LINE_ITEM_ADDED")) {
            String orderId = intent.getStringExtra("com.clover.intent.extra.ORDER_ID");
            String lineItemId = intent.getStringExtra("com.clover.intent.extra.LINE_ITEM_ID");
            String itemId = intent.getStringExtra("com.clover.intent.extra.ITEM_ID");
            AddDiscountActivity mainActivity = new AddDiscountActivity();
            mainActivity.addDiscount(orderId);
        }
    }
}

and this is addDiscount() method of AddDiscountActivity class for add discount to order.

public void addDiscount(String orderId) {
    try {
        final Discount discount = new Discount();
        discount.setPercentage(10l);
        discount.setName("10% Discount");
        orderConnector.addDiscount(orderId, discount);
    } catch (Exception e) {
        Log.e("Exception", " "+e);
    }
}

I am not able to find out why this event is not working. Please let me know if I am missing anything. OR Is there any setting in clover account to active the intent functionality? I am new for this clover functionality so your help would be really appreciated.

Thanks.

6 comments
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Jeffrey Blattman avatar image Jeffrey Blattman ♦♦ commented ·

Where are you registering an unregistering your broadcast receiver?

0 Likes 0 ·
dipen avatar image dipen commented ·

Hi Jeff,

In AndroidMAnifest.xml file i have registered the receiver event of LINEITEMADDED.

<receiver android:name=".EventReceiver" android:exported="true" android:label="Event Receiver" &gt;="" <intent-filter=""> <action android:name="com.clover.intent.action.LINE_ITEM_ADDED"/> <category android:name="android.intent.category.DEFAULT"/> </intent-filter> </receiver>

Is this wrong or we need to register receiver event in other file?

Thanks,

0 Likes 0 ·
Jeffrey Blattman avatar image Jeffrey Blattman ♦♦ commented ·

Can you please try removing the category from the filter? We don't broadcast with a category.

0 Likes 0 ·
dipen avatar image dipen commented ·

Hi Jeff,

I removed the category from filter, but still it's not working. However I am not able to find out the intent is receiving or not. I am using the Genymotion emulator(we don't have clover device) to test Clover APP. On Genymotion we don't have logs, so for receiving intent confirmation, I have applied the discount to order when new line item is added. Also I have used the "MODIFYORDER" and "ORDERCREATED" event for testing purpose, but these are also not working.

Is this correct way to find out the intent or we need to do it on other way?

Thanks,

0 Likes 0 ·
Jeffrey Blattman avatar image Jeffrey Blattman ♦♦ commented ·

Has your app been run at least once? Android won't let you receive broadcasts unless your app has been started (an activity or service start).

Other than that, your code looks fine. Can you post the logcatlogs into pastebin and provide a link? Not sure what you mean by "don't have logs", you should be able to run "adb logcat" against a Genymotion instance.

0 Likes 0 ·
Show more comments

0 Answers

Welcome to the
Clover Developer Community