Intent 拨打电话

package com.second;


import java.util.ArrayList;
import java.util.List;


import com.bean.BeanFriend;
import com.first.R;


import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;


public class SecondFrActivity extends Activity {
BeanFriend beanFriend;
private RelativeLayout relativeLayout;
private TextView textname, textbirthday, texthome, textwork, textphone;
List<BeanFriend> list = new ArrayList<BeanFriend>();


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second_f_item);
initView();
initData();


}


private void initData() {
Intent intent = getIntent();
beanFriend = (BeanFriend) intent.getSerializableExtra("beanFriend");
textname.setText(beanFriend.getFname());
textphone.setText(beanFriend.getFphone());
textbirthday.setText(beanFriend.getFbirthday());
texthome.setText(beanFriend.getFhomeaddress());
textwork.setText(beanFriend.getFworkaddress());


}


private void initView() {
textname = (TextView) findViewById(R.id.fname);
textphone = (TextView) findViewById(R.id.textphonenum);
textbirthday = (TextView) findViewById(R.id.birthday);
texthome = (TextView) findViewById(R.id.texthome);
textwork = (TextView) findViewById(R.id.textwork);
// 点击RelativeLayout电话布局拨打电话
relativeLayout = (RelativeLayout) findViewById(R.id.fcallphone);
relativeLayout.setOnClickListener(new View.OnClickListener() {


@Override
public void onClick(View arg0) {
//beanFriend为人所在Bean类。
String number = beanFriend.getFphone();
Uri tel = Uri.parse( number);
Intent returnIntent = new Intent(Intent.ACTION_CALL, tel);
startActivity(returnIntent);
/*
* Toast.makeText(SecondFrActivity.this, "拨打电话",
* Toast.LENGTH_LONG) .show();
*/
}
});


}

}


1.报错为android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.CALL dat= }

 Uri tel = Uri.parse( number);改为Uri tel = Uri.parse("tel:" + number);

就不会报错了。不知道为什么。都是String类型。反正加上就对了。

报错为:java.lang.SecurityException: Permission Denial: starting Intent

是因为没有加权限。

在配置文件<manifest>加入 <uses-permission android:name="android.permission.CALL_PHONE"/>  即可


进步都是一步步的。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值