无法通过pyjnius创建AdRequest实例

时间:2014-08-06 16:48:40

标签: android admob kivy pyjnius

我试图在Kivy上安装AdMob。我成功导入AdRequest但无法创建其实例。

AdRequest = autoclass("com.google.android.gms.ads.AdRequest")
print "AdRequest: ", AdRequest
print dir(AdRequest)

在logcat中,我可以通过dir()看到AdRequest的属性和方法:

AdRequest <class 'jnius.reflect.com.google.android.gms.ads.AdRequest'>
['DEVICE_ID_EMULATOR', 'ERROR_CODE_INTERNAL_ERROR', 'ERROR_CODE_INVALID_REQUEST',        
'ERROR_CODE_NETWORK_ERROR', 'ERROR_CODE_NO_FILL', 'GENDER_FEMALE', 'GENDER_MALE',   
'GENDER_UNKNOWN', 'MAX_CONTENT_URL_LENGTH', '__class__', '__cls_storage', 
'__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', 
'__init__', '__javaclass__', '__javaconstructor__', '__module__', '__new__',   
'__pyx_vtable__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', 
'__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'equals', 'getBirthday', 
'getClass', 'getContentUrl', 'getCustomEventExtrasBundle', 'getGender', 'getKeywords', 
'getLocation', 'getNetworkExtras', 'getNetworkExtrasBundle', 'hashCode', 
'isTestDevice', 'notify', 'notifyAll', 'toString', 'wait']

AttributeError: type object 'com.google.android.gms.ads.AdRequest' has no attribute    
'Builder'
Python for android ended.

我找不到Builder方法 https://developer.android.com/reference/com/google/android/gms/ads/AdRequest.html 它是构建AdRequest的类方法

1 个答案:

答案 0 :(得分:1)

问题是AdRequest.Builder不是方法,而是嵌套类。所以你需要使用nested class syntax

来引入正确的课程
AdBuilder = autoclass('com.google.android.gms.ads.AdRequest$Builder')