80,351
社区成员
发帖
与我相关
我的任务
分享
Intent intent = new Intent();
intent.setAction("Intent.ACTION_CALL");
//intent.addCategory("android.intent.category.DEFAULT");
intent.setData(Uri.parse("tel:"+num));
Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+num));
MainActivity.java
package com.fufu.phonoNumber;
import android.net.Uri;
import android.content.Intent;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.EditText;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button) this.findViewById(R.id.taking);
button.setOnClickListener(new ButtonClickListener());
}
private final class ButtonClickListener implements View.OnClickListener{
public void onClick(View v) {
EditText edittext = (EditText) findViewById(R.id.number);
String num = edittext.getText().toString();
Intent intent = new Intent();
intent.setAction("Intent.ACTION_CALL");
//intent.addCategory("android.intent.category.DEFAULT");
intent.setData(Uri.parse("tel:"+num));
//Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+num));
MainActivity.this.startActivity(intent);//方法内部会自动为Intent添加类别android.intent.category.DEFAULT
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.fufu.phonoNumber"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<uses-permission android:maxSdkVersion="17" android:name="android.permission.CALL_PHONE"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.fufu.phonoNumber.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Intent intent = new Intent();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:"+ number));