1

错误:无法保存哪个视图具有焦点,因为焦点视图 com.android.internal.policy.impl.PhoneWindow$DecorView@40556f58 没有 id

这是我的代码:

Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
                    startActivityForResult(intent,PICK_CONTACT );

结果:

    public void onActivityResult(int reqCode, int resultCode, Intent data)
    {
        super.onActivityResult(reqCode, resultCode, data);

            switch(reqCode)
            {
               case (PICK_CONTACT):
                 if (resultCode == Activity.RESULT_OK)
                 {
                     Uri contactData = data.getData();
                     Cursor c = managedQuery(contactData, null, null, null, null);

                      if (c.moveToFirst()) 
                      {
                          String id =   
                              c.getString(c.getColumnIndexOrThrow(ContactsContract.Contacts._ID));

                          String hasPhone =
                              c.getString(c.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));

                          if (hasPhone.equalsIgnoreCase("1")) 
                          {
                              Cursor phones = getContentResolver().query( 
                              ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null, 
                              ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ id, 
                              null, null);

                              phones.moveToFirst();
                              String phn_no = phones.getString(phones.getColumnIndex("data1"));
                              String name = c.getString(c.getColumnIndex(StructuredPostal.DISPLAY_NAME));

                              //Toast.makeText(this, "contact info : "+ phn_no+"\n"+name, Toast.LENGTH_LONG).show();

                              phn_no = phn_no.replace("+", "");
                              phn_no = phn_no.replace("-", "");
                              phn_no = phn_no.replace(" ", "");
                              phn_no = phn_no.replace("#", "");
                              phn_no = phn_no.replace("@", "");
                              phn_no = phn_no.replace("*", "");
                              phn_no = phn_no.replace(".", "");

                              System.out.println("masuk method ini");

//                            Toast.makeText(parent, phn_no, 2).show();

                              txtHape.setText(phn_no);

                          }
                      }
                 }
            }
       }

我还在清单上添加了许可,例如:

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

我应该怎么做才能解决这个问题?

4

0 回答 0