附加图片到联系人 [英] Attach an image to a contact

查看:194
本文介绍了附加图片到联系人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有完全相同的问题描述这里

I am having exactly the same problem as described here.

我试图用这个意图:
android.provider.ContactsContract.Intents.ATTACH_IMAGE

开始的活动,可以让用户选择一个联系人的图像附加。结果
听起来很适合我,但遗憾的是导致一个 ActivityNotFoundException

code:

import android.provider.ContactsContract;  
...  
try {  
    Intent myIntent = new Intent();  
    myIntent.setAction(ContactsContract.Intents.ATTACH_IMAGE);  
    myIntent.setData(imageUri);  
    startActivity(myIntent);  
} catch (ActivityNotFoundException anfe) {  
    Log.e("ImageContact", 
            "Firing Intent to set image as contact failed.", anfe);  
    showToast(this, "Firing Intent to set image as contact failed.");  
}

我找不到在code以上的任何错误。在 imageUri 是正确的以下code为正常使用:

I cannot find any error in the code above. The imageUri is correct for following code is working perfectly:

code:

try {  
    Intent myIntent = new Intent();  
    myIntent.setAction(Intent.ACTION_ATTACH_DATA);
    myIntent.setData(imageUri);  
    startActivity(myIntent);  
} catch (ActivityNotFoundException anfe) {  
    Log.e("ImageContact", 
            "Firing Intent to set image as contact failed.", anfe);  
    showToast(this, "Firing Intent to set image as contact failed.");  
}

由于在链接中提到这导致了另一个菜单获取到的接触之前。这是可以接受的,但并不完美。

As mentioned in the link this results in a another menu before getting to the contacts. That is acceptable but not perfect.

推荐答案

如果你已经知道文件的路径,你可以使用:

If you already know the file path you can use:

values.put(Images.Media.DISPLAY_NAME, fileName);
values.put(Images.Media.DATE_ADDED, currentTime);
values.put(Images.Media.MIME_TYPE, "image/jpeg");
values.put(Images.Media.ORIENTATION, 0);
values.put(Images.Media.DATA, filePath);
values.put(Images.Media.SIZE, size);

getContentResolver().insert(Images.Media.EXTERNAL_CONTENT_URI, values);

这样没有NEAD打开一个位图流,如果你已经有一个文件。

This way no nead to open a bitmap stream if you already have the file.

这篇关于附加图片到联系人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆