2014-12-23 2 views
-1

확인 버튼을 클릭하면 전화를 걸고 싶습니다. 지금은 오류가 점점 오전android fragment class에서 전화를 거는 방법?

오류 메시지가 여기에

12-23 17:19:39.547: E/AndroidRuntime(4095): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.CALL dat=91 90-37-300100 flg=0x10000000 } 

내 코드

public class ContactFragment extends Fragment { 
private View parentView; 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
    //return inflater.inflate(R.layout.contact, container, false); 
    parentView = inflater.inflate(R.layout.contact, container, false); 
    setUpViews(); 
    return parentView; 
} 

private void setUpViews() { 
    parentView.findViewById(R.id.contact_phone).setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View arg0) { 
      // TODO Auto-generated method stub 
      // Creating alert Dialog with two Buttons 
      AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity()); 
      // Setting Dialog Title 
      alertDialog.setTitle("Do you want to call?"); 
      // Setting Dialog Message 
      alertDialog.setMessage("+91 XXXXXXXXXX"); 
      // Setting Icon to Dialog 
      //alertDialog.setIcon(R.drawable.warning); 
      // Setting Negative "NO" Button 
      alertDialog.setNegativeButton("No", 
        new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, 
           int which) { 
          // Write your code here to execute after dialog 
          dialog.cancel(); 
         } 
        }); 
      // Setting Positive "Yes" Button 
      alertDialog.setPositiveButton("Yes", 
        new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, 
           int which) { 
          // Write your code here to execute after dialog 
          Intent callIntent = new Intent(Intent.ACTION_CALL); 
          callIntent.setData(Uri.parse("91 XXXXXXXXXX")); 
          callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
          startActivity(callIntent); 

         } 
        }); 

      // Showing Alert Message 
      alertDialog.show(); 
     } 
    }); 
} } 

답변

1

변경이 :이와

callIntent.setData(Uri.parse("91 XXXXXXXXXX")); 

:

callIntent.setData(Uri.parse("tel:" + "91XXXXXXXXXX")); 
+0

감사합니다. –

1

변경

callIntent.setData(Uri.parse("91 XXXXXXXXXX")); 

함께

callIntent.setData(Uri.parse("tel:" + "91 XXXXXXXXXX")); 

번호를 추가하기 전에 "tel :"을 추가하기 만하면됩니다.

기본적으로 아래 코드와 같이 호출해야합니다.

Intent intent = new Intent(Intent.ACTION_DIAL); 
intent.setData(Uri.parse("tel:"+phone)); 
startActivity(intent); 
3

그냥 당신의 코드를 대체 :

Intent callIntent = new Intent(Intent.ACTION_CALL); 
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
callIntent.setData(Uri.parse("tel:" + "91XXXXXXXXXX")); 
getActivity().startActivity(callIntent); 

와의 통화 권한을 추가 매니페스트 파일

+0

정답입니다. startActivity (callIntent)를 사용할 수 없습니다. 조각에서 직접. getActivity와 startActivity (callIntent)를 사용하여 여기에 주어진대로 먼저 액티비티를 가져와야한다. –

관련 문제