Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Instrumentation.ActivityMonitor not monitoring Intent.ACTION_CALL

I have a simple test case for testing whether an outgoing call is initiated on a button click or not.

public void testCalling(){
    IntentFilter callFilter = new IntentFilter();
    callFilter.addAction(Intent.ACTION_CALL);
    callFilter.addCategory(Intent.CATEGORY_DEFAULT);
    callFilter.addDataScheme("tel:");
    ActivityMonitor mMonitor = new ActivityMonitor(callFilter, null, false);
    getInstrumentation().addMonitor(mMonitor);

    mSolo.clickOnText("CALL");

    assertTrue(0 < mMonitor.getHits());
    sendKeys(KeyEvent.KEYCODE_ENDCALL); 
}

Although the Intent is called(the outgoing call is made), my ActivityMonitor fails to register it. The Stack trace is

05-28 17:11:09.183: I/ActivityManager(71): Starting activity: Intent { act=android.intent.action.CALL dat=tel:+xxxxxxx cmp=com.android.phone/.OutgoingCallBroadcaster }

Please help

The only other resource that i could find was this discussion which ended without any solution on android developers group

like image 612
vKashyap Avatar asked Oct 07 '22 17:10

vKashyap


2 Answers

I thought to have the same problem. Later I found out that my activity monitor didn't work because robotium registers it's own monitor that always hits, blocking any other monitors including mine.

like image 192
Oderik Avatar answered Oct 12 '22 10:10

Oderik


After having the same issue and playing around a bit, I got it to work.

Take the colon off "tel". Then you should have a hit on your monitor.

    public void testMakeCall(){
        IntentFilter filter = new IntentFilter(Intent.ACTION_CALL);
        filter.addCategory(Intent.CATEGORY_DEFAULT);
        filter.addDataScheme("tel");

        ActivityMonitor activityMonitor = getInstrumentation().addMonitor(filter, null, false);

        makeCall();

        assertTrue(activityMonitor.getHits() == 1);
    }
like image 45
Kevin Avatar answered Oct 12 '22 10:10

Kevin