0

我正在开发需要导入本地 .vcf 文件的 Android 2.3.3 应用程序。我尝试导入它来启动意图

final String pathDownload = Environment.getExternalStorageDirectory()+"/vcard1.vcf";

    Intent i = new Intent();
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    i.setAction(android.content.Intent.ACTION_VIEW);
    i.setDataAndType(Uri.parse(pathDownload), "text/x-vcard");
    activity.startActivity(i);

但是即使文件存在并且可以从任何文件管理器轻松导入,这也会导致 IOException。有任何想法吗?

07-26 12:10:04.995: I/ActivityManager(307): START {act=android.intent.action.VIEW dat=/storage/sdcard0/vcard1.vcf typ=text/x-vcard flg=0x10000000 cmp=com.android.contacts/.vcard.ImportVCardActivity u=0} from pid 7681
07-26 12:10:05.050: I/ActivityManager(307): START {cmp=com.android.contacts/.vcard.SelectAccountActivity u=0} from pid 7604
07-26 12:10:05.057: I/SelectAccountActivity(7604): The number of available accounts: 2
07-26 12:10:05.057: I/AccountSelectionUtil(7604): The number of available accounts: 2
07-26 12:10:10.065: I/ActivityManager(307): Displayed com.android.contacts/.vcard.SelectAccountActivity: +5s15ms (total +5s26ms)
07-26 12:10:19.190: I/VCardImport(7604): Starting vCard import using Uri /storage/sdcard0/vcard1.vcf
07-26 12:10:19.198: I/VCardImport(7604): Bind to VCardService.
07-26 12:10:19.307: I/VCardImport(7604): Connected to VCardService. Kick a vCard cache thread (uri: [/storage/sdcard0/vcard1.vcf])
07-26 12:10:19.307: I/VCardImport(7604): vCard cache thread starts running.
07-26 12:10:19.315: I/VCardImport(7604): Copy a Uri to app local storage (/storage/sdcard0/vcard1.vcf -> import_tmp_0.vcf)
07-26 12:10:19.315: E/VCardImport(7604): IOException during caching vCard
07-26 12:10:19.315: E/VCardImport(7604): java.io.FileNotFoundException: No content provider: /storage/sdcard0/vcard1.vcf
07-26 12:10:19.315: E/VCardImport(7604):    at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:708)
07-26 12:10:19.315: E/VCardImport(7604):    at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:612)
07-26 12:10:19.315: E/VCardImport(7604):    at android.content.ContentResolver.openInputStream(ContentResolver.java:447)
07-26 12:10:19.315: E/VCardImport(7604):    at com.android.contacts.vcard.ImportVCardActivity$VCardCacheThread.copyTo(ImportVCardActivity.java:392)
07-26 12:10:19.315: E/VCardImport(7604):    at com.android.contacts.vcard.ImportVCardActivity$VCardCacheThread.run(ImportVCardActivity.java:300)
07-26 12:10:19.315: I/VCardImport(7604): Finished caching vCard.
07-26 12:10:19.339: I/ActivityManager(307): Displayed com.android.contacts/.vcard.ImportVCardActivity: +14s303ms

更新:将意图更改为:

     Intent i = new Intent(android.content.Intent.ACTION_VIEW,   Uri.parse(pathDownload));
     i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
     i.setType("text/x-vcard");
     activity.startActivity(i);

我可以导入任何 2.1 vcf 文件。但是,如果我尝试使用 3.0 vcf 进行相同操作,则会发生以下情况:

07-26 15:55:40.783: I/VCardImport(2453): Bind to VCardService.
07-26 15:55:40.923: I/VCardImport(2453): Connected to VCardService. Kick a vCard cache thread (uri: [file:///storage/sdcard0/Podcasts/vcard1.vcf])
07-26 15:55:40.923: I/VCardImport(2453): vCard cache thread starts running.
07-26 15:55:40.931: I/VCardImport(2453): Copy a Uri to app local storage (file:///storage/sdcard0/Podcasts/vcard1.vcf -> import_tmp_1.vcf)
07-26 15:55:40.939: W/vCard(2453): Property name unsupported by vCard 2.1: N
07-26 15:55:40.939: W/vCard(2453): Property name unsupported by vCard 2.1: ORG
07-26 15:55:40.947: W/vCard(2453): The value unsupported by TYPE of 1: 
07-26 15:55:40.955: E/VCardImport(2453): Maybe the file is in wrong format
07-26 15:55:40.955: E/VCardImport(2453): com.android.vcard.exception.VCardException: Space exists at the beginning of the line
07-26 15:55:40.955: E/VCardImport(2453):    at com.android.vcard.VCardParserImpl_V30.getNonEmptyLine(VCardParserImpl_V30.java:124)
07-26 15:55:40.955: E/VCardImport(2453):    at com.android.vcard.VCardParserImpl_V21.parseItem(VCardParserImpl_V21.java:306)
07-26 15:55:40.955: E/VCardImport(2453):    at com.android.vcard.VCardParserImpl_V21.parseItems(VCardParserImpl_V21.java:289)
07-26 15:55:40.955: E/VCardImport(2453):    at com.android.vcard.VCardParserImpl_V21.parseOneVCard(VCardParserImpl_V21.java:226)
07-26 15:55:40.955: E/VCardImport(2453):    at com.android.vcard.VCardParserImpl_V21.parse(VCardParserImpl_V21.java:932)
07-26 15:55:40.955: E/VCardImport(2453):    at com.android.vcard.VCardParser_V30.parse(VCardParser_V30.java:87)
07-26 15:55:40.955: E/VCardImport(2453):    at com.android.contacts.vcard.ImportVCardActivity$VCardCacheThread.constructImportRequest(ImportVCardActivity.java:478)
07-26 15:55:40.955: E/VCardImport(2453):    at com.android.contacts.vcard.ImportVCardActivity$VCardCacheThread.run(ImportVCardActivity.java:339)
07-26 15:55:40.955: I/VCardImport(2453): Finished caching vCard.

清单权限:

<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
4

1 回答 1

0
java.io.FileNotFoundException: No content provider: /storage/sdcard0/vcard1.vcf

它清楚地说文件不可用

并且您是否在清单文件中给予了许可?

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
于 2012-07-26T10:27:35.857 回答