Skip to content

Formulating intents

metall0id edited this page Nov 26, 2014 · 8 revisions

It is possible to build an Intent directly with reflection:

intent = self.new("android.content.Intent")

intent.setAction("android.intent.action.VIEW")

self.getContext().startActivity(intent)

However, drozer provides a simple API to reduce the amount of code required:

from drozer import android

intent = android.Intent(action="android.intent.action.VIEW")

self.getContext().startActivity(intent.buildIn(self))

The benefit of using drozer's API is that it provides helpful short-cuts for adding flags and extras to the intent.

Setting the Component

When specifying the component, a tuple containing the package and component names should be passed:

intent = android.Intent(component=("com.android.browser", "com.android.browser.BrowserActivity"))

Adding Flags

drozer accepts a list of flags, either as hexadecimal strings, or as constant names as defined in the Android SDK:

intent.flags.append("0x10000000")
intent.flags.append("ACTIVITY_NEW_TASK")

drozer will combine all specified flags, and pass a single hexadecimal string.

Passing Extras

Intents can carry messages or commands inside of them in the form of extras. Applications may want to pass additional information inside of the intents they send to one another, possibly containing the data to perform a task on, or any other user-defined task to initiate from the received data.

As with flags, drozer can pass many extras in an Intent:

intent.extras.append(("string", "mykey", "myvalue"))

Extras of different types can be passed by setting the first argument (type). drozer supports: boolean, byte, char, double, float, integer, short, string.

In all instances, the value should be specified as a string, containing a suitable value that will be cast to the correct type:

intent.extras.append(("boolean", "mybool", "true"))
intent.extras.append(("integer", "myint", "42"))
intent.extras.append(("double", "mydouble", "3.14"))

Additional Examples

Initiate a phone call:

from drozer import android

intent = android.Intent(action="android.intent.action.CALL", data_uri="tel:+271234567", flags=["ACTIVITY_NEW_TASK"])
self.getContext().startActivity(intent.buildIn(self))