android 打電話程式的實現

來源:互聯網
上載者:User

布局以及片

代碼

Strings.xml------------------------------------------------------------------------------------

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">day01_msm</string>
    <string name="action_settings">Settings</string>
    <string name="hello_world">Hello world!</string>
    <string name="phone_num">請輸入手機號</string>
    <string name="phone_center">請輸入內容</string>
    <string name="phone_btn">發送</string>

</resources>

 

 

--------------------------------------------------------------------------------------------------------------

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.day01_msm"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />
    <uses-permission android:name="android.permission.WRITE_SMS"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.day01_msm.SmsActivity"
            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>

 

------------------------------------------------------------------------------------------------------------

package com.example.day01_msm;

import java.util.ArrayList;

import android.os.Bundle;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.telephony.SmsManager;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class SmsActivity extends Activity {
 private Button button_viem;
 private EditText edit_phone;
 private EditText edit_sms;
 
 
 

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sms);
       
       
        button_viem = (Button) findViewById(R.id.phone_btn);
        edit_phone = (EditText) findViewById(R.id.edit_num);
        edit_sms = (EditText) findViewById(R.id.edit_center);
       
        button_viem.setOnClickListener(new View.OnClickListener() {
   
   @Override
   public void onClick(View arg0) {
    String phone_num = edit_phone.getText().toString();
    String edit_content = edit_sms.getText().toString();
    SmsManager smsManager = SmsManager.getDefault();
    PendingIntent pendingIntent = PendingIntent.getBroadcast(
      SmsActivity.this, 0, new Intent(), 0);
    ArrayList<String> contents = smsManager.divideMessage(edit_content);
    for (String c : contents) {
     smsManager.sendTextMessage(phone_num, null, c, pendingIntent, null);
    }
    Toast.makeText(SmsActivity.this, "正在傳送簡訊", Toast.LENGTH_LONG).show();
    
   }
  });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.sms, menu);
        return true;
    }
   
}

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.