Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically click on Android notification

I am black-box testing an application by using the Robotium framework. The app under test send a notification in the status bar each time I install a new application. I would like to click on that notification, but I still did not find a proper way to do it.

When I manually click on one notification I get this logcat lines:

I/ActivityManager(  148): START {flg=0x14000000 cmp=com.test.package/.activity.FrontActivity bnds=[0,38][240,86] (has extras) u=0} from pid -1
I/ActivityManager(  148): START {flg=0x14000000 cmp=com.test.package/.activity.ResultActivity u=0} from pid 8600
I/ActivityManager(  148): Displayed com.test.package/.activity.FrontActivity: +1s183ms
I/ActivityManager(  148): Displayed com.test.package/.activity.ResultActivity: +744ms

I know Robotium cannot test 2 different applications at the same time, as well as I know you can't get the notification of an external application.

I also tried to get the pending intent and fire it up by using the following code:

Context context = this.getInstrumentation().getTargetContext().getApplicationContext();
String intentClassString = "com.test.package.activity.FrontActivity";
Class<?> intentClass = null;

try {
    intentClass = Class.forName(intentClassString);
} catch (ClassNotFoundException e) {
    e.printStackTrace();
}

Intent intent = new Intent(context, intentClass);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_NO_CREATE);

try {
    pendingIntent.send();
} catch (CanceledException e) {
    e.printStackTrace();
}

The activity is actually showed, but it is different from what I obtain by manually invoking it. I think something is wrong in the context I pass, or the way I call the pending intent.

Any hint about this issue? Is there a better way to simulate the click on a notification?

like image 889
Andrea Avatar asked Dec 16 '12 19:12

Andrea


1 Answers

You can trigger the swipe on notification bar and tap event on notification.

Refer commands :

adb shell input swipe 100 500 400 100 1000

adb shell input tap 400 400

by changing the arguments you can use these commands.

like image 198
Ranjith KP Avatar answered Nov 01 '22 00:11

Ranjith KP