• 打电话发短信


    代码

    package org.jgw.hello;

    import java.util.ArrayList;

    import android.app.Activity;
    import android.content.Intent;
    import android.net.Uri;
    import android.os.Bundle;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.Toast;
    import android.telephony.SmsManager;
    import android.view.*;

    public class HellowordActivity extends Activity {
        /** Called when the activity is first created. */
        
        EditText mobel;
        EditText SMS;
        
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            
            mobel=(EditText) findViewById(R.id.editText1);
            Button button1=(Button)this.findViewById(R.id.button1);
            button1.setOnClickListener(new ButtonClickListener());
            
            
            SMS=(EditText) findViewById(R.id.editText2);
            Button sendSMS=(Button) findViewById(R.id.button2);
            sendSMS.setOnClickListener(new SendSMS());
            
        }
        
        private final class SendSMS implements  View.OnClickListener
        {
            public void onClick(View v) {
                
                String ls_number=mobel.getText().toString();
                String ls_content=SMS.getText().toString();
                
                SmsManager  manager=SmsManager.getDefault();
                
                ArrayList<String> texts=manager.divideMessage(ls_content);
                for(String text:texts)
                {
                    manager.sendTextMessage(ls_number, null, text, nullnull);
                }
                
                Toast.makeText(HellowordActivity.this, R.string.sendsuccess, Toast.LENGTH_LONG).show();
            }    
        }
         
        //打电话
        private final class ButtonClickListener implements  View.OnClickListener
        {    
            public void onClick(View v) {
                
                String ls_number=mobel.getText().toString();
                Intent intent=new Intent();
                intent.setAction("android.intent.action.CALL");
                //intent.addCategory("android.intent.category.DEFAULT");
                intent.setData(Uri.parse("tel:"+ls_number));        
                startActivity(intent);//把意图传给操作系统
            }    
        }    

     mainfest

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

        <uses-sdk android:minSdkVersion="8" />
        <uses-permission android:name="android.permission.CALL_PHONE"/>
        <uses-permission android:name="android.permission.SEND_SMS"/>
        
        <application
            
    android:icon="@drawable/ic_launcher"
            android:label
    ="@string/app_name" >
            <activity
                
    android:label="@string/app_name"
                android:name
    =".HellowordActivity" >
                <intent-filter >
                    <action android:name="android.intent.action.MAIN" />

                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>

    </manifest> 

  • 相关阅读:
    浅谈线段树
    并查集最简单讲解
    mysql索引原理深度解析
    算法、数据结构可视化
    php算法题---对称的二叉树
    php算法题---连续子数组的最大和
    Jsoup一个简短的引论——采用Java抓取网页数据
    宏定义详细信息
    解决java.sql.SQLException: ORA-01789: query block has incorrect number of result columns
    BZOJ 2435 NOI2011 道路建设 BFS/DFS
  • 原文地址:https://www.cnblogs.com/kuailewangzi1212/p/2605737.html
Copyright © 2020-2023  润新知