我的应用程序有一个RecyclerView列表中的餐厅,其中每个餐厅都有一个按钮来拨打电话。从ViewHolder请求电话权限
该电话适用于除23之外的所有API。问题是应用程序必须请求许可才能拨打电话,但它无法从非活动类中执行此操作。
我试过传递上下文,但它没有为我工作。
以下是将餐厅绑定到CardView的方法。
public void bind(final Restaurant restaurant) {
name.setText(restaurant.getName());
address.setText(restaurant.getAddress());
city.setText(String.format("%05d %s (%s)", restaurant.getZip(), restaurant.getCity(), restaurant.getRegion()));
switch (restaurant.getCountry()) {
case "France":
country.setText(R.string.france);
break;
case "Spain":
country.setText(R.string.spain);
break;
case "Poland":
country.setText(R.string.poland);
break;
case "Portugal":
country.setText(R.string.portugal);
}
latitude = restaurant.getLatitude();
longitude = restaurant.getLongitude();
phoneCall.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+restaurant.getPhone()));
//
// Here I should request the permissions
//
v.getContext().startActivity(intent);
}
});
navigation.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Uri gmmIntentUri = Uri.parse("google.navigation:q=" + latitude + "," + longitude);
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
v.getContext().startActivity(mapIntent);
}
});
}
任何解决方案?在此先感谢
在谷歌 “运行时允许” –