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();
*/
}
});
}
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类型。反正加上就对了。
2 报错为:java.lang.SecurityException: Permission Denial: starting Intent
是因为没有加权限。
在配置文件<manifest>加入 <uses-permission android:name="android.permission.CALL_PHONE"/> 即可
进步都是一步步的。