Search code examples
androidpythonmonkeyrunnerandroidviewclient

AndroidViewClient remove package and broadcastreceiver


I am using the AndroidViewClient library, and it works perfectly fine. I want to know how do I remove a package and access the methods listed here:

http://developer.android.com/tools/help/MonkeyDevice.html

I tried using MonkeyRunner but androidviewclient doesnt support it anymore and shows an import error.

Is there any means to use the methods listed in the link ? Here is my code :

import os
import re
import time

# This must be imported before MonkeyRunner and MonkeyDevice,
# otherwise the import fails.
# PyDev sets PYTHONPATH, use it
try:
    for p in os.environ['PYTHONPATH'].split(':'):
        if not p in sys.path:
            sys.path.append(p)
except:
    pass

try:
    sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))
except:
    pass

from com.dtmilano.android.viewclient import *

package = 'com.android.vending'
activity = 'com.android.vending.AssetBrowserActivity'
component = package + "/" + activity
device, serialno = ViewClient.connectToDeviceOrExit()
vc = ViewClient(device, serialno)
vc.dump(window='-1')
device.removePackage('com.mypackage.myapp')

I get the following error :

 File "test1.py", line 38, in <module>
    device.removePackage('com.mypackage.myapp')
AttributeError: AdbClient instance has no attribute 'removePackage'

Solution

  • Unfortunately not all the methods have been ported to AdbClient yet. In the meantime you can use device.shell('pm uninstall your.package.name')