Android 星触觉法产生误差
我正在尝试编写一个简单的应用程序来调用某个特定的号码。 我在清单上写了使用Call_Phone的权限,但我的startActivity仍然标记为红色。 有人知道如何解决这个问题吗Android 星触觉法产生误差,android,Android,我正在尝试编写一个简单的应用程序来调用某个特定的号码。 我在清单上写了使用Call_Phone的权限,但我的startActivity仍然标记为红色。 有人知道如何解决这个问题吗 package com.example.programmer.gate; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.support.v7.app.ActionBarAc
package com.example.programmer.gate;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.Button;
public class Gate extends ActionBarActivity {
Button b;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gate);
b = (Button) findViewById(R.id.bt);
b.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:123");
**startActivity(callIntent);**
}
});
}
}
检查权限
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:+123"));
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
startActivity(callIntent);
如果应用程序的targetSdkVersion大于22,则需要运行时权限。这可能是您的应用程序中出现错误的原因。因此,请检查您的gradle文件以确认。我认为这对您有帮助。您的代码还可以 只需在AndroidManifest.xml中添加用户权限 这样地
它会产生什么错误?它是语法的还是运行时的?
<uses-permission android:name="android.permission.CALL_PHONE"/>