我想启动一个 android 添加联系人活动。但我也想启动联系人的意图插入操作。我的代码有什么问题。
只是我想开始添加联系人活动,其中包含已添加的电话和号码等预填充数据。
import kivy
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.floatlayout import FloatLayout
from jnius import cast
from jnius import autoclass
PythonActivity = autoclass('org.renpy.android.PythonActivity')
Intent = autoclass('android.content.Intent')
Uri = autoclass('android.net.Uri')
Intents = autoclass("android.provider.ContactsContract$Intents")
ContactsContract = autoclass("android.provider.ContactsContract")
Contacts = autoclass("android.provider.ContactsContract$Contacts")
class Main(FloatLayout):
def go_site(self):
# create the intent
'''
intent = Intent()
intent.setAction(Intent.ACTION_INSERT)
intent.setData(Uri.parse("content://contacts/people/"))
#############################################################
intent = Intent()
intent.setAction(Intent.ACTION_INSERT_OR_EDIT)
intent.setType(Contacts.CONTENT_ITEM_TYPE)
'''
intent = Intent()
intent.setAction(Intents.Insert.ACTION)
intent.setType(ContactsContract.RawContacts.CONTENT_TYPE)
#intent.putExtra(Intents.Insert.EMAIL, "")
# PythonActivity.mActivity is the instance of the current Activity
# BUT, startActivity is a method from the Activity class, not from our PythonActivity.
# We need to cast our class into an activity and use it
currentActivity = cast('android.app.Activity', PythonActivity.mActivity)
currentActivity.startActivity(intent)
class MainApp(App):
def on_pause(self):
# Here you can save data if needed
return True
def on_resume(self):
# Here you can check if any data needs replacing (usually nothing)
pass
def build(self):
return Main()
if __name__ == '__main__':
MainApp().run()