|
给别人写的,放出来给大家做参考
模拟器可用,真机需要完善,有时间的铁子可以研究下改个真机版
- import net.sourceforge.cardme.io.CompatibilityMode
- import net.sourceforge.cardme.io.VCardWriter
- import net.sourceforge.cardme.vcard.VCardImpl
- import net.sourceforge.cardme.vcard.arch.VCardVersion
- import net.sourceforge.cardme.vcard.types.FNType
- import net.sourceforge.cardme.vcard.types.TelType
- //def t = ["13100001111","13200002222","13300003333"]
- def t = "13100001111,13200002222,13300003333"
- tl = t.split(",")
- exec("pm clear com.android.providers.contacts")
- sleep(1000)
- print('开始写入通讯录')
- writeTels(tl)
- print('ok')
- sleep(1000)
- def writeTels(def tels){
- VCardWriter writer = new VCardWriter(VCardVersion.V3_0, CompatibilityMode.RFC2426);//用户把VCard转换为字符
- FileWriter fw = new FileWriter(new File("sdcard/contacts.vcf"));//把VCard数据(字符)写入文件
- // for (def tel in tels){
- VCardImpl vc = new VCardImpl();//创建一个名片
- //def tel = "1" + JsDroid2.rnd(31,88) + JsDroid2.rnd(10000000,99999999)
- def tel = "13911112222"
- print('写入通讯录:'+tel)
- //设置名片名字(FNType)。Sets the FN type. This type must be set in the VCard and cannot be omitted, it can however be left with all empty values.文档说这个值必须设置,不能忽略。
- vc.setFN(new FNType(tel))
- //给名片添加一个电话号码。名片是可以有多个号码的
- vc.addTel(new TelType(tel));
- writer.setVCard(vc);
- String str = writer.buildVCardString();//把名片对象转化为字符
- fw.append(str);//写入文件
- // }
- fw.flush();
- fw.close();
- }
复制代码
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
|