仰天大笑出门去,我辈岂是蓬蒿人。这篇文章主要讲述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
}
}
推荐阅读
- Android studio / IntelliJ构建窗口自动显示
- 在Android上获取应用程序安装日期
- 在Windows上获取Android的SHA键
- PhoneGap - 后退按钮上的android退出
- Ionic Build Android - build.gradle文件不断添加重复的编译行并导致构建失败
- 将电子应用转移到cordova app
- 将OneSignal插件添加到Ionic App后生成APK时出错
- Ionic app,错误(..main.ts模块构建失败:错误:ENOENT)
- 从Android访问Windows WebService获取IP地址