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 に答える