Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android显示自己的应用程序图标以联系_Android - Fatal编程技术网

android显示自己的应用程序图标以联系

android显示自己的应用程序图标以联系,android,Android,在我的android项目中,我想在android联系人信息中显示我的应用程序图标调用功能。在这张图片中,whatsapp如何显示图标 因此,我使用以下代码:-- private static final IM_LABEL=“测试协议”; 私有静态最终日志\u TAG=“LOG” /** *此方法在默认联系人的IM字段下添加我的帐户 *应用 * *用我的自定义协议标记。 * *@param contentResolver *内容解析器 *@param-uid *来自android的用户id

在我的android项目中,我想在android联系人信息中显示我的应用程序图标调用功能。在这张图片中,whatsapp如何显示图标

因此,我使用以下代码:--

private static final IM_LABEL=“测试协议”;
私有静态最终日志\u TAG=“LOG”
/**
*此方法在默认联系人的IM字段下添加我的帐户
*应用
* 
*用我的自定义协议标记。
* 
*@param contentResolver
*内容解析器
*@param-uid
*来自android的用户id
*@param帐户
*帐户名
*/
public static void updateIMContactField(ContentResolver ContentResolver,
字符串(uid,字符串帐户){
ContentValues ContentValues=新ContentValues();
contentValues.put(contacts contract.Data.RAW\u CONTACT\u ID,
整数.parseInt(uid));
contentValues.put(contacts contract.Data.MIMETYPE,
Contacts contract.CommonDataTypes.Im.CONTENT\u ITEM\u TYPE);
contentValues.put(contacts contract.commondatatypes.Im.TYPE,
contacts contract.commondatatypes.Im.TYPE\u CUSTOM);
contentValues.put(contacts contract.commondatatypes.Im.LABEL、Im\u LABEL);
contentValues.put(contacts contract.commonDataTypes.Im.PROTOCOL,
contacts contract.commondatatypes.Im.PROTOCOL\u CUSTOM);
contentValues.put(contacts contract.commondatatypes.Im.CUSTOM_协议,
IM_标签);
contentValues.put(contacts contract.commondatatypes.Im.DATA,account);
ArrayList ops=新的ArrayList();
添加操作(ContentProviderOperation
.newInsert(contacts合同.Data.CONTENT\u URI)
.withValues(contentValues.build());
试一试{
contentResolver.applyBatch(contacts contract.AUTHORITY,ops);
}捕获(例外e){
Log.d(Log_标签,“无法更新联系人的IM字段”);
}
}
/**
*此方法在默认联系人应用程序中删除IM条目。
* 
*@param contentResolver
*内容解析器
*@param-uid
*来自android的用户id
*@param帐户
*帐户名
*/
公共静态void removemContactField(ContentResolver ContentResolver,
字符串(uid,字符串帐户){
ArrayList ops=新的ArrayList();
添加操作(ContentProviderOperation
.newDelete(Data.CONTENT\u URI)
.选举(
Contacts contract.Data.RAW_CONTACT_ID+“=”和“
+Contacts contract.Data.MIMETYPE+“=”和“
+Contacts contract.CommonDataTypes.Im.DATA
+ " = ?",
新字符串[]{
字符串.valueOf(uid),
Contacts contract.CommonDataTypes.Im.CONTENT\u ITEM\u TYPE,
account}.build());
试一试{
contentResolver.applyBatch(contacts contract.AUTHORITY,ops);
}捕获(例外e){
Log.d(Log_标签,“无法删除联系人的IM字段”);
}
}
/**
*此方法在默认联系人应用程序中删除IM所有条目
* 
*@param contentResolver
*内容解析器
*/
公共静态void deleteAllIMContactField(ContentResolver ContentResolver){
ArrayList ops=新的ArrayList();
添加操作(ContentProviderOperation
.newDelete(Data.CONTENT\u URI)
.选举(
联系人contract.Data.MIMETYPE
+“=?和”
+ContactsContract.CommonDataTypes.Im.CUSTOM_协议
+ "= ?",
新字符串[]{
Contacts contract.CommonDataTypes.Im.CONTENT\u ITEM\u TYPE,
IM_LABEL}.build());
试一试{
contentResolver.applyBatch(contacts contract.AUTHORITY,ops);
}捕获(例外e){
Log.d(Log_标签,
“删除联系人的所有IM字段时发生异常。”);
}
}
现在我的问题是,我可以添加多少字段。是否有任何限制?这是实现此要求的唯一过程吗

private static final IM_LABEL = "Test protocol";
 private static final LOG_TAG = "Log"
    /**
 * This method add my account under IM field at default Contact
 * application
 * 
 * Labeled with my custom protocol.
 * 
 * @param contentResolver
 *            content resolver
 * @param uid
 *            User id from android
 * @param account
 *            account name
 */
public static void updateIMContactField(ContentResolver contentResolver,
        String uid, String account) {

    ContentValues contentValues = new ContentValues();

    contentValues.put(ContactsContract.Data.RAW_CONTACT_ID,
            Integer.parseInt(uid));
    contentValues.put(ContactsContract.Data.MIMETYPE,
            ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE);
    contentValues.put(ContactsContract.CommonDataKinds.Im.TYPE,
            ContactsContract.CommonDataKinds.Im.TYPE_CUSTOM);
    contentValues.put(ContactsContract.CommonDataKinds.Im.LABEL, IM_LABEL);
    contentValues.put(ContactsContract.CommonDataKinds.Im.PROTOCOL,
            ContactsContract.CommonDataKinds.Im.PROTOCOL_CUSTOM);
    contentValues.put(ContactsContract.CommonDataKinds.Im.CUSTOM_PROTOCOL,
            IM_LABEL);

    contentValues.put(ContactsContract.CommonDataKinds.Im.DATA, account);

    ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
    ops.add(ContentProviderOperation
            .newInsert(ContactsContract.Data.CONTENT_URI)
            .withValues(contentValues).build());

    try {
        contentResolver.applyBatch(ContactsContract.AUTHORITY, ops);
    } catch (Exception e) {
        Log.d(LOG_TAG, "Can't update Contact's IM field.");
    }
}

/**
 * This method remove IM entry at default Contact application.
 * 
 * @param contentResolver
 *            content resolver
 * @param uid
 *            User id from android
 * @param account
 *            account name
 */
public static void removeIMContactField(ContentResolver contentResolver,
        String uid, String account) {
    ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();

    ops.add(ContentProviderOperation
            .newDelete(Data.CONTENT_URI)
            .withSelection(
                    ContactsContract.Data.RAW_CONTACT_ID + "=? and "
                            + ContactsContract.Data.MIMETYPE + "=? and "
                            + ContactsContract.CommonDataKinds.Im.DATA
                            + " = ?",
                    new String[] {
                            String.valueOf(uid),
                            ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE,
                            account }).build());

    try {
        contentResolver.applyBatch(ContactsContract.AUTHORITY, ops);
    } catch (Exception e) {
        Log.d(LOG_TAG, "Can't delete Contact's IM field.");
    }
}

/**
 * This method remove IM all entries at default Contact application 
 * 
 * @param contentResolver
 *            content resolver
 */
public static void deleteAllIMContactField(ContentResolver contentResolver) {
    ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();

    ops.add(ContentProviderOperation
            .newDelete(Data.CONTENT_URI)
            .withSelection(
                    ContactsContract.Data.MIMETYPE
                            + "= ? and "
                            + ContactsContract.CommonDataKinds.Im.CUSTOM_PROTOCOL
                            + "= ?",
                    new String[] {
                            ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE,
                            IM_LABEL }).build());

    try {
        contentResolver.applyBatch(ContactsContract.AUTHORITY, ops);
    } catch (Exception e) {
        Log.d(LOG_TAG,
                "An exception occurred when deleting all IM field of Contact.");
    }
}