Issue
I'm trying to make a call from DialogFragment but the (packageManager) doesn't accept how to solve it?!
class ItemDetkFragment : DialogFragment() {
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
val v: View= inflater.inflate(R.layout.fragment_item_detk, container, false)
v.car_typee.text= car_item.type
v.item_typee.text= car_item.item_type
v.modele.text= car_item.modele
v.pricee.text= car_item.price+ " JD"
if (car_item.number> 0) {
v.numberr.text= "available"
v.numberr.setTextColor(Color.GREEN)
} else {
v.numberr.text= "Not available"
v.numberr.setTextColor(Color.RED)
}
Picasso.with(activity).load(car_item.picUrl).into(v.photo)
v.contactPhone.setOnClickListener {
val phoneNum = "855394839583"// the number for testing
val i = Intent(Intent.ACTION_DIAL)
i.data = Uri.parse("tel:$phoneNum")
if (i.resolveActivity(packageManager) != null) { //the
problem is here in (((((packageManager)))))it is in red!!!
startActivity(i)
}
}
return v
}
}
as you can see from the picture the (packageManager) is in red, how to fix it!!
Solution
Try this:
PackageManager packageManager = getActivity().getPackageManager();
if (i.resolveActivity(packageManager) != null) {
startActivity(i)
}
Answered By - Juan Daniel Ornella
Answer Checked By - Clifford M. (JavaFixing Volunteer)