Android: strange behaviour in QuickContactBadge

2019-02-19 06:06发布

问题:

i'm trying to use the QuickContactBadge; i would like to get an effect like this:

but when i write this code:

    QuickContactBadge badge = (QuickContactBadge) findViewById(R.id.badge_small);  
    badge.assignContactFromPhone("831-555-1212", true);  

I don't see the badge but i am redirected to the Contact page.

Here is layout.xml:

  <?xml version="1.0" encoding="utf-8"?>
  <LinearLayout  
    xmlns:android="http://schemas.android.com/apk/res/android"  
    android:layout_width="wrap_content"  
    android:layout_height="wrap_content"  
    android:orientation="vertical">  
    <QuickContactBadge  
        android:id="@+id/badge_small"  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content"  
        android:src="@drawable/icon"></QuickContactBadge>  
    </LinearLayout>  

How can i see the badge?

Thanks in advance c.

回答1:

You need to add the READ_CONTACTS permission to your AndroidManifest.xml file:

<uses-permission android:name="android.permission.READ_CONTACTS" />


回答2:

1) A caution: you must use API Level 5 or above to use this function.

2) For taking to you on contact page: The function of this badge works in such a way that if a contact is already there then it will show you the quick contact badge else it will take you the "add contact" screen with this phone no pre filled in contact's info.

So now, you need to save a contact with the phone no defined. After saving the contact, when you will click on the button next time, it will show you the desired results.