android.permission.CALL_PHONE

仰天大笑出门去,我辈岂是蓬蒿人。这篇文章主要讲述android.permission.CALL_PHONE相关的知识,希望能为你提供帮助。
我有一个通话方法。一切都很好。但是我想在按下按钮时访问它,应用程序继续请求调用权限。我该如何着手实现这个功能?

public class Menu_A extends AppCompatActivity implements OnClickListener {private InterstitialAd mInterstitialAd; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_menu_); Button one = (Button) findViewById(R.id.btnActTwo); one.setOnClickListener(this); Button two = (Button) findViewById(R.id.btnAftor); two.setOnClickListener(this); mInterstitialAd = new InterstitialAd(this); mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712"); AdRequest adRequest = new AdRequest.Builder().build(); mInterstitialAd.loadAd(adRequest); mInterstitialAd.setAdListener(new AdListener() { @Override public void onAdLoaded() { if(mInterstitialAd.isLoaded()) { mInterstitialAd.show(); }}}); }@Override public void onClick(View v) {switch (v.getId()) {case R.id.btnActTwo: Intent intent = new Intent(this, eda.class); startActivity(intent); break; case R.id.btnAftor:Intent callIntent = new Intent(Intent.ACTION_CALL); callIntent.setData(Uri.parse("tel:8********")); if (ActivityCompat.checkSelfPermission(Menu_A.this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {return; } startActivity(callIntent); break; }}}

答案试试这个 :
case R.id.btnAftor:Intent callIntent = new Intent(Intent.ACTION_CALL); callIntent.setData(Uri.parse("tel:8********")); if (ActivityCompat.checkSelfPermission(Menu_A.this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(Menu_A.this, new String[]{Manifest.permission.CALL_PHONE}, 1); } startActivity(callIntent); break;

【android.permission.CALL_PHONE】在您的Menu_A课程中,检查权限
@Override public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { switch (requestCode) {case 1: {if (grantResults.length > 0 & & grantResults[0] == PackageManager.PERMISSION_GRANTED) { Toast.makeText(getApplicationContext(), "Permission granted", Toast.LENGTH_SHORT).show(); call_action(); } else { Toast.makeText(getApplicationContext(), "Permission denied", Toast.LENGTH_SHORT).show(); } return; }// other 'case' lines to check for other // permissions this app might request } }


    推荐阅读