Testing with Activity Monitor

by Brian Phagan » Tue, 12 Apr 2011 07:23:45 GMT


Sponsored Links
 I am trying to write unit tests for my application.  I have a button
that initiates a call, and to test it I am trying to use an Activity
Monitor to block the call, but for some reason the call is allowed to
execute, causing the test to fail.  My test case is written as
follows:

public void test2Launches() {
                Instrumentation instr = getInstrumentation();
                IntentFilter callFilter = new IntentFilter(Intent.ACTION_CALL);
                Instrumentation.ActivityMonitor monitor =
instr.addMonitor(callFilter, null, true);
                mActivity.runOnUiThread(
                                new Runnable() {

                                        public void run() {
                                                mCallButton.requestFocus();

                                        }
                                }
                );
                this.sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);
                assertEquals(1, monitor.getHits());
        }

Any help on why this isn't working would be appreciated.

-- 



Re: Testing with Activity Monitor

by Dianne Hackborn » Tue, 12 Apr 2011 07:28:00 GMT


 What is the error you are getting?







-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

-- 


Sponsored Links


Re: Testing with Activity Monitor

by Brian Phagan » Tue, 12 Apr 2011 07:43:43 GMT


 The Dialer activity is not blocked, it is allowed to launch.  Also,
the assertEquals(1, monitor.getHits()) fails with a value of 0.





-- 



Re: Re: Testing with Activity Monitor

by Dianne Hackborn » Tue, 12 Apr 2011 07:51:05 GMT


 Your intent filter also needs to handle CATEGORY_DEFAULT.  This should be
the exact same thing you would put in the manifest to handle an intent.









-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

-- 



Re: Testing with Activity Monitor

by Brian Phagan » Tue, 12 Apr 2011 08:24:26 GMT


  have added the category to the intent filter, but still no luck.
Code now looks like this:

public void test2Launches() {
Instrumentation instr = getInstrumentation();
IntentFilter callFilter = new IntentFilter(Intent.ACTION_CALL);
callFilter.addCategory(Intent.CATEGORY_DEFAULT);
Instrumentation.ActivityMonitor monitor =
instr.addMonitor(callFilter, null, true);
assertNotNull(mCallButton);
mActivity.runOnUiThread(
new Runnable() {

public void run() {
mCallButton.requestFocus();

}
}
);
this.sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);
assertEquals(1, monitor.getHits());
}

On Apr 11, 6:50pm, Dianne Hackborn <hack...@android.com> wrote:

--



Re: Re: Testing with Activity Monitor

by Dianne Hackborn » Tue, 12 Apr 2011 08:29:13 GMT


 hat do you see in the log as the actual intent being started?

On Mon, Apr 11, 2011 at 5:24 PM, Brian Phagan <phagan....@gmail.com> wrote:




--
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails. All such
questions should be posted on public forums, where I and others can see and
answer them.

--



Re: Testing with Activity Monitor

by Brian Phagan » Tue, 12 Apr 2011 08:41:49 GMT


 4-12 00:38:32.894: INFO/ActivityManager(59): Starting activity:
Intent { act=android.intent.action.CALL dat=tel:5733415688
cmp=com.android.phone/.OutgoingCallBroadcaster }


On Apr 11, 7:28pm, Dianne Hackborn <hack...@android.com> wrote:

--



Re: Re: Testing with Activity Monitor

by Dianne Hackborn » Tue, 12 Apr 2011 09:50:58 GMT


 o that's the intent you need to intercept -- CALL and the "tel:" scheme.
Also of course the DEFAULT category.

On Mon, Apr 11, 2011 at 5:41 PM, Brian Phagan <phagan....@gmail.com> wrote:




--
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails. All such
questions should be posted on public forums, where I and others can see and
answer them.

--



Other Threads

1. Test on a real HTC Magic via the web

Hi,

I work for a company called Perfecto Mobile (used to be Nexperience).
See www.perfectomobile.com .
We enable access to real mobile devices via the web. You can install
your app on the device and test it as if you were holding the device
in your hands.
We just introduced the HTC Magic to our service and I thought it might
be interesting for you to check it out if you are having a hard time
getting a Magic. Simply register to the service and get the free trial
to start using it.

Enjoy!

Yossi

--~--~---------~--~----~------------~-------~--~----~

2. How to add the image on surface view?

Hi,

I am trying to add an image on surface view.

I have coded some thing like this:

 public void surfaceCreated(final SurfaceHolder holder)
{
                  // The Surface has been created, acquire the camera and
tell it where
                  // to draw.




                         Runnable r = new Runnable()
                         {
                                 public void run()
                                 {
                                         Rect rect = new Rect();
                                         rect.set(0, 0, 60, 60);
                                        Canvas canvas = 
mHolder.lockCanvas(rect);
                                        InputStream is = 
context.getResources().openRawResource
(R.drawable.karaoke48x48);
                                        //Bitmap bitmap = 
BitmapFactory.decodeResource(getResources
(), R.drawable.karaoke48x48);
                                        Bitmap bitmap = 
BitmapFactory.decodeStream(is);
                                        Paint p = new Paint();
                                        if(bitmap != null)
                                                canvas.drawBitmap(bitmap, 0,0, 
p);
                                        mHolder.unlockCanvasAndPost(canvas);
                                 //mHolder.

                                 }
                         };
                         new Thread(r).start();

                         try
                         {
                                  
videoRecorder.setPreviewDisplay(mHolder.getSurface());
                         }
                         catch (Exception e)
                         {
                               e.printStackTrace();
                         }

                         if (videoRecorder != null)
                         {
                              try
                              {
                                  videoRecorder.prepare();
                                  System.out.println("video recorder 
prepared.");
                                  videoRecorder.start();
                                  System.out.println("video recorder started.");
                              }
                              catch (IllegalStateException e)
                              {
                                   // TODO Auto-generated catch block
                                   e.printStackTrace();
                              }
                              catch (Exception ex)
                              {
                                   ex.printStackTrace();
                              }
                          }
}

I got an image over the screen, but no preview is there.

But when I see the recorded media file, it is showing the recorded
video.

Can any one please help me to solve this?

Thanks,
Manoj.
--~--~---------~--~----~------------~-------~--~----~

3. Playing multiple sounds at once?

4. Accelerometer and dpad

5. Error messages in logcat while browsing!

6. escaping string in SQLite

7. Testing OpenGL rendering in Java outside of Android?