我正在尝试进行一个简单的点击动作,它会调用一个特定的数字,我正处于代码的最后一个阶段,我无法看到我做错了什么。目前它的startActivity动作似乎呈现错误,但我不知道为什么我看了多个教程,我可以看到任何不同。当在startActivity之上时,它告诉我需要呼叫权限?
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
setContentView(R.layout.activity_home);
//On load the program automatically hides the taskbar.
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
Button b = (Button) this.findViewById(R.id.BTNCall);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
Intent PhoneCall = new Intent(Intent.ACTION_CALL);
PhoneCall.setData(Uri.parse("tel:123"));
startActivity(PhoneCall);
}
});
}
我还在android清单中添加了一个权限
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
答案 0 :(得分:0)
您应该将目标SDK版本设置为lvl 22或更低版本,因为对于lvl 23,您需要在运行时向用户请求权限,请查看there以获得更好的解释。
答案 1 :(得分:-1)
由于您是从OnClickListener进行的,因此&#34;此&#34;指向您正在实现的clickListener类的指针引用,您需要获取对您的活动的引用:
MyActivityClassName.this.startActivity() //Dont know your class name
那应该摆脱红色亮点。
如果您仍然遇到崩溃,我们将需要logcat输出来解决它。
希望这有帮助。