【问题标题】:How to select more contacts from my contact list to send an sms如何从我的联系人列表中选择更多联系人发送短信
【发布时间】:2013-06-03 16:14:05
【问题描述】:

现在我只能从我手机中的联系人中选择一个联系人,我想在我的联系人列表中向更多人发送短信,我该如何发送。

现在我无法在手机中添加更多联系人,即使手动也无法编辑文本,也无法从联系人列表中获取。

我想在我的联系人列表中发送更多联系电话以发送短信。我该怎么办

public class SendSMSActivity extends Activity {
Button buttonSend,get;
private static final int CONTACT_PICKER_RESULT = 1001;
EditText phoneNo;
EditText textSMS;
int columnIndex_number;
static String stringNumber;
String sms;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.about);
    phoneNo = (EditText)findViewById(R.id.editText1);
    textSMS = (EditText) findViewById(R.id.editText2);
    get = (Button) findViewById(R.id.button1);
    get.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
             Intent contactPickerIntent = new Intent(Intent.ACTION_PICK,
                    Contacts.CONTENT_URI);
            startActivityForResult(contactPickerIntent, CONTACT_PICKER_RESULT);


        }
        });

    Intent intent1= getIntent(); // gets the previously created intent
    final String firstKeyName = intent1.getStringExtra("firstKeyName");


    textSMS.setText(firstKeyName);

    buttonSend = (Button) findViewById(R.id.button2);    
    buttonSend.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v){
          try {

              String sms =  textSMS.getText().toString().trim();
                Toast.makeText(getApplicationContext(), phoneNo.getText().toString()+firstKeyName,
                        Toast.LENGTH_LONG).show();
            SmsManager smsManager = SmsManager.getDefault();
            smsManager.sendTextMessage(phoneNo.getText().toString(), null, firstKeyName, null, null);
            Toast.makeText(getApplicationContext(), "SMS Sent!",
                        Toast.LENGTH_LONG).show();

          } catch (Exception e) {
            Toast.makeText(getApplicationContext(),
                "SMS faild, please try again later!",
                Toast.LENGTH_LONG).show();
            e.printStackTrace();
          }
          finish();


        }
    });
}

 @Override  
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
 if (resultCode == RESULT_OK) {  
    switch (requestCode) {  
    case CONTACT_PICKER_RESULT:

        Cursor cursor = null;  
        String phoneNumber = "";
        List<String> allNumbers = new ArrayList<String>();
        int phoneIdx = 0;
        try {  
            Uri result = data.getData();  
            String id = result.getLastPathSegment();  
            cursor = getContentResolver().query(Phone.CONTENT_URI, null, Phone.CONTACT_ID + "=?", new String[] { id }, null);  
            phoneIdx = cursor.getColumnIndex(Phone.DATA);
            if (cursor.moveToFirst()) {
                while (cursor.isAfterLast() == false) {
                    phoneNumber = cursor.getString(phoneIdx);
                    allNumbers.add(phoneNumber);
                    phoneNo.setText(cursor.getString(phoneIdx));

                    cursor.moveToNext();
                }
            } else {
                //no results actions
            }  
        } catch (Exception e) {  
           //error actions
        } finally {  
            if (cursor != null) {  
                cursor.close();
            } 
        }  
        break;  
    }  
} else {
   //activity result error actions
}  
}
}

Logcaterror 显示:

06-07 14:06:05.546: E/AndroidRuntime(780): FATAL EXCEPTION: main
06-07 14:06:05.546: E/AndroidRuntime(780): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.jsonandroid/com.example.jsonandroid.ContactActivity}; have you declared this activity in your AndroidManifest.xml?
06-07 14:06:05.546: E/AndroidRuntime(780):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1618)
06-07 14:06:05.546: E/AndroidRuntime(780):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
06-07 14:06:05.546: E/AndroidRuntime(780):  at android.app.Activity.startActivityForResult(Activity.java:3370)
06-07 14:06:05.546: E/AndroidRuntime(780):  at android.app.Activity.startActivityForResult(Activity.java:3331)
06-07 14:06:05.546: E/AndroidRuntime(780):  at com.example.jsonandroid.SendSMSActivity$1.onClick(SendSMSActivity.java:42)
06-07 14:06:05.546: E/AndroidRuntime(780):  at android.view.View.performClick(View.java:4202)
06-07 14:06:05.546: E/AndroidRuntime(780):  at android.view.View$PerformClick.run(View.java:17340)
06-07 14:06:05.546: E/AndroidRuntime(780):  at android.os.Handler.handleCallback(Handler.java:725)
06-07 14:06:05.546: E/AndroidRuntime(780):  at android.os.Handler.dispatchMessage(Handler.java:92)
06-07 14:06:05.546: E/AndroidRuntime(780):  at android.os.Looper.loop(Looper.java:137)
06-07 14:06:05.546: E/AndroidRuntime(780):  at android.app.ActivityThread.main(ActivityThread.java:5039)
06-07 14:06:05.546: E/AndroidRuntime(780):  at java.lang.reflect.Method.invokeNative(Native Method)
06-07 14:06:05.546: E/AndroidRuntime(780):  at java.lang.reflect.Method.invoke(Method.java:511)
06-07 14:06:05.546: E/AndroidRuntime(780):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-07 14:06:05.546: E/AndroidRuntime(780):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-07 14:06:05.546: E/AndroidRuntime(780):  at dalvik.system.NativeStart.main(Native Method)

【问题讨论】:

  • 嘿,我可以编辑我发布的代码。您在评论中发布的链接使用了内置的短信工具。
  • 你编辑你的答案代码吗?
  • 我建议您阅读文档。我无法详细解释一切。 get.xml 是一样的。我做了一些小的改动。根据您的要求进行修改。如果您有疑问,请提出新问题,我无法在评论中解释所有内容
  • 好的,伙计,你更改的代码在哪里,.bcz 现在我只使用你的代码@Raghunandan,你能告诉我你在哪里更改
  • 查看帖子中的编辑部分。有疑问提出一个新问题。停止评论这么多

标签: java android sms


【解决方案1】:

您可以从联系人列表中获取所有联系人并将其显示在列表中。您可以使用复选框选择联系人并单击按钮。导航到 SendMessage 活动并输入短信内容并发送消息

我认为有更好的方法来处理复选框。对于复选框获取所选项目,我点击以下链接。

https://groups.google.com/forum/?fromgroups#!topic/android-developers/No0LrgJ6q2M

您还可以获取您只需要的列。下面获取所有不好的列。

  Cursor phones = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null,null, null);

get.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

<ListView
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:layout_above="@+id/button1"
   android:id="@+id/lv"/>
 <Button
     android:id="@+id/button1"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignParentBottom="true"
     android:layout_alignParentLeft="true"
     android:layout_marginLeft="44dp"
     android:text="Send" />

 </RelativeLayout>

MainActivity.java

公共类 MainActivity 扩展 Activity 实现 OnItemClickListener{

ArrayList<String> name1 = new ArrayList<String>();
ArrayList<String> phno1 = new ArrayList<String>();
ArrayList<String> phno0 = new ArrayList<String>();
MyAdapter ma ;
Button show,add;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);


    setContentView(R.layout.get);
    getAllCallLogs(this.getContentResolver());
    ListView lv= (ListView) findViewById(R.id.lv);
     ma = new MyAdapter();
    lv.setAdapter(ma);
    lv.setOnItemClickListener(this); 
    lv.setItemsCanFocus(false);
    lv.setTextFilterEnabled(true);
    // adding
    add = (Button) findViewById(R.id.button1);
    add.setOnClickListener(new OnClickListener()
    {

        @Override
        public void onClick(View v) {
              StringBuilder checkedcontacts= new StringBuilder();
            System.out.println(".............."+ma.mCheckStates.size());
            for(int i = 0; i < name1.size(); i++)

                {
                if(ma.mCheckStates.get(i)==true)
                {
                      phno0.add(phno1.get(i).toString()) ;
                     checkedcontacts.append(name1.get(i).toString());
                     checkedcontacts.append("\n");

                }
                else
                {
           System.out.println("..Not Checked......"+name1.get(i).toString());
                }


            }
                Toast.makeText(MainActivity.this, checkedcontacts,1000).show();
                Intent intent = new Intent(new Intent(MainActivity.this,SendMessage.class));
                intent.putStringArrayListExtra("name",phno0);
                startActivity(intent); 

        }       
    });


}

@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
    // TODO Auto-generated method stub
     ma.toggle(arg2);
}

public  void getAllCallLogs(ContentResolver cr) {

    Cursor phones = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null,null, null);
    while (phones.moveToNext())
    {
      String name=phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
      String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
      System.out.println(".................."+phoneNumber); 
      name1.add(name);
      phno1.add(phoneNumber);
    }

    phones.close();
 }
class MyAdapter extends BaseAdapter implements CompoundButton.OnCheckedChangeListener
{  private SparseBooleanArray mCheckStates;
   LayoutInflater mInflater;
    TextView tv1,tv;
    CheckBox cb;
    MyAdapter()
    {
        mCheckStates = new SparseBooleanArray(name1.size());
        mInflater = (LayoutInflater)MainActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }
    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return name1.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub

        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        View vi=convertView;
        if(convertView==null)
         vi = mInflater.inflate(R.layout.row, null); 
         TextView tv= (TextView) vi.findViewById(R.id.textView1);
         tv1= (TextView) vi.findViewById(R.id.textView2);
         cb = (CheckBox) vi.findViewById(R.id.checkBox1);
         tv.setText("Name :"+ name1.get(position));
         tv1.setText("Phone No :"+ phno1.get(position));
         cb.setTag(position);
         cb.setChecked(mCheckStates.get(position, false));
         cb.setOnCheckedChangeListener(this);

        return vi;
    }
     public boolean isChecked(int position) {
            return mCheckStates.get(position, false);
        }

        public void setChecked(int position, boolean isChecked) {
            mCheckStates.put(position, isChecked);
        }

        public void toggle(int position) {
            setChecked(position, !isChecked(position));
        }
    @Override
    public void onCheckedChanged(CompoundButton buttonView,
            boolean isChecked) {
        // TODO Auto-generated method stub

         mCheckStates.put((Integer) buttonView.getTag(), isChecked);                 
    }       
}   
}

SendMessage.java

   public class SendMessage extends Activity {

EditText ed1,ed2;
ArrayList<String> sendlist = new ArrayList<String>();
Button b1;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sendmessage);
    ed1= (EditText)findViewById(R.id.editText1);
    ed2= (EditText)findViewById(R.id.editText2);
    Bundle extras = getIntent().getExtras();
    if(extras!=null)
    {
        sendlist = extras.getStringArrayList("name");
        if(sendlist!=null)
        {
        for(int i=0;i<sendlist.size();i++)
        {
            ed1.append(sendlist.get(i).toString());
            ed1.append(";");
        }
    }
    }
    else
    {
        Toast.makeText(getApplicationContext(), "null",
                Toast.LENGTH_LONG).show();
    }
    b1 = (Button) findViewById(R.id.button1);
    b1.setOnClickListener(new OnClickListener()
    {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            for(int i=0;i<sendlist.size();i++)
            {

                if(ed2.getText().length()>0)
                {
                  try {
                        SmsManager smsManager = SmsManager.getDefault();

                        smsManager.sendTextMessage(sendlist.get(i).toString(), null, ed2.getText().toString(), null, null);

                        Toast.makeText(getApplicationContext(), "SMS Sent!",
                                    Toast.LENGTH_LONG).show();
                      } catch (Exception e) {
                        Toast.makeText(getApplicationContext(),
                            "SMS faild, please try again later!",
                            Toast.LENGTH_LONG).show();
                        e.printStackTrace();
                      }
                }
            }

        }

    });
}   
}

发送消息.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<EditText
    android:id="@+id/editText1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="18dp"
    android:ems="10" >

    <requestFocus />
</EditText>

<EditText
    android:id="@+id/editText2"
    android:layout_width="wrap_content"
    android:layout_height="200dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/editText1"
    android:layout_marginTop="62dp"
    android:ems="10" />

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignTop="@+id/editText1"
    android:layout_centerHorizontal="true"
    android:text="Phone Numbers" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/editText1"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="37dp"
    android:text="Message" />

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView2"
    android:layout_alignParentBottom="true"
    android:text="Send" />

</RelativeLayout>

你需要添加这两个权限

 <uses-permission android:name="android.permission.READ_CONTACTS"/>
 <uses-permission android:name="android.permission.SEND_SMS" />

编辑:

首先打开 SendMessage 活动。单击editext1 旁边的获取按钮。导航到显示所有联系人的 MainActivity 并使用复选框进行选择。单击发送将完成活动并返回短信活动。在editext 1中可以看到选中的联系人,其余的都一样。

我使用 startActivity 作为结果。这比我能做的更多。请相应修改。

  public class SendMessage extends Activity {

EditText ed1,ed2;
static int ResultCode= 12;
ArrayList<String> sendlist = new ArrayList<String>();
Button b1,b2;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sendmessage);
    b2 = (Button) findViewById(R.id.button2);
    ed1= (EditText)findViewById(R.id.editText1);
    ed2= (EditText)findViewById(R.id.editText2);
    b1 = (Button) findViewById(R.id.button1);
    b2.setOnClickListener(new OnClickListener()
     {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        Intent i = new Intent(SendMessage.this, MainActivity.class);
        startActivityForResult(i, ResultCode);
    }

 });

    b1.setOnClickListener(new OnClickListener()
    {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            for(int i=0;i<sendlist.size();i++)
            {

                if(ed2.getText().length()>0)
                {
                  try {
                        SmsManager smsManager = SmsManager.getDefault();

                        smsManager.sendTextMessage(sendlist.get(i).toString(), null, ed2.getText().toString(), null, null);

                        Toast.makeText(getApplicationContext(), "SMS Sent!",
                                    Toast.LENGTH_LONG).show();
                      } catch (Exception e) {
                        Toast.makeText(getApplicationContext(),
                            "SMS faild, please try again later!",
                            Toast.LENGTH_LONG).show();
                        e.printStackTrace();
                      }
                }
            }

        }

    });
}


protected void onActivityResult(int requestCode, int resultCode, Intent data) {

      if (requestCode == ResultCode) {

         if(resultCode == RESULT_OK){      
             sendlist  =data.getStringArrayListExtra("name");
             if(sendlist!=null)
                {
                for(int i=0;i<sendlist.size();i++)
                {
                    ed1.append(sendlist.get(i).toString());
                    ed1.append(";");
                }

         }
         if (resultCode == RESULT_CANCELED) {    

         }
      }
    }
}
}

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<EditText
    android:id="@+id/editText1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="18dp"
    android:ems="10" >

    <requestFocus />
</EditText>

<EditText
    android:id="@+id/editText2"
    android:layout_width="wrap_content"
    android:layout_height="200dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/editText1"
    android:layout_marginTop="62dp"
    android:ems="10" />

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignTop="@+id/editText1"
    android:layout_centerHorizontal="true"
    android:text="Phone Numbers" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/editText1"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="37dp"
    android:text="Message" />

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView2"
    android:layout_alignParentBottom="true"
    android:text="Send" />

<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/textView2"
    android:layout_alignBottom="@+id/textView2"
    android:layout_alignParentRight="true"
    android:text="Get" />

 </RelativeLayout>

主活动

    public class MainActivity extends Activity implements OnItemClickListener{


ArrayList<String> name1 = new ArrayList<String>();
ArrayList<String> phno1 = new ArrayList<String>();
ArrayList<String> phno0 = new ArrayList<String>();
MyAdapter ma ;
Button send;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);


    setContentView(R.layout.get);
    getAllCallLogs(this.getContentResolver());
    ListView lv= (ListView) findViewById(R.id.lv);
     ma = new MyAdapter();
    lv.setAdapter(ma);
    lv.setOnItemClickListener(this); 
    lv.setItemsCanFocus(false);
    lv.setTextFilterEnabled(true);
    send = (Button) findViewById(R.id.button1);
    send.setOnClickListener(new OnClickListener()
    {

        @Override
        public void onClick(View v) {
              StringBuilder checkedcontacts= new StringBuilder();
            System.out.println(".............."+ma.mCheckStates.size());
            for(int i = 0; i < name1.size(); i++)

                {
                if(ma.mCheckStates.get(i)==true)
                {
                      phno0.add(phno1.get(i).toString()) ;
                     checkedcontacts.append(name1.get(i).toString());
                     checkedcontacts.append("\n");

                }
                else
                {
                    System.out.println("..Not Checked......"+name1.get(i).toString());
                }


            }
                Toast.makeText(MainActivity.this, checkedcontacts,1000).show();
                Intent returnIntent = new Intent();
                 returnIntent.putStringArrayListExtra("name",phno0);
                 setResult(RESULT_OK,returnIntent);     
                 finish();

        }       
    });
}

@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
    // TODO Auto-generated method stub
     ma.toggle(arg2);
}

public  void getAllCallLogs(ContentResolver cr) {

    Cursor phones = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null,null, null);
    while (phones.moveToNext())
    {
      String name=phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
      String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
      System.out.println(".................."+phoneNumber); 
      name1.add(name);
      phno1.add(phoneNumber);
    }

    phones.close();
 }
class MyAdapter extends BaseAdapter implements CompoundButton.OnCheckedChangeListener
{  private SparseBooleanArray mCheckStates;
   LayoutInflater mInflater;
    TextView tv1,tv;
    CheckBox cb;
    MyAdapter()
    {
        mCheckStates = new SparseBooleanArray(name1.size());
        mInflater = (LayoutInflater)MainActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }
    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return name1.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub

        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        View vi=convertView;
        if(convertView==null)
         vi = mInflater.inflate(R.layout.row, null); 
         tv= (TextView) vi.findViewById(R.id.textView1);
         tv1= (TextView) vi.findViewById(R.id.textView2);
         cb = (CheckBox) vi.findViewById(R.id.checkBox1);
         tv.setText("Name :"+ name1.get(position));
         tv1.setText("Phone No :"+ phno1.get(position));
         cb.setTag(position);
         cb.setChecked(mCheckStates.get(position, false));
         cb.setOnCheckedChangeListener(this);

        return vi;
    }
     public boolean isChecked(int position) {
            return mCheckStates.get(position, false);
        }

        public void setChecked(int position, boolean isChecked) {
            mCheckStates.put(position, isChecked);
        }

        public void toggle(int position) {
            setChecked(position, !isChecked(position));
        }
    @Override
    public void onCheckedChanged(CompoundButton buttonView,
            boolean isChecked) {
        // TODO Auto-generated method stub

         mCheckStates.put((Integer) buttonView.getTag(), isChecked);                 
    }       
}   
} 

行.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="15dp"
    android:layout_marginTop="34dp"
    android:text="TextView" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/checkBox1"
    android:layout_alignLeft="@+id/textView1"
    android:text="TextView" />

<CheckBox
    android:id="@+id/checkBox1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/textView1"
    android:layout_marginRight="22dp"
    android:layout_marginTop="23dp" />
 </RelativeLayout 

清单文件

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

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

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.sendsmstoall.SendMessage"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
     <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >

    </activity>
</application>

</manifest>

【讨论】:

  • 老兄,我的代码,我该如何添加,有很多困惑如何在我的代码中做这件事,我必须在我的代码中添加第一行
  • 我无法帮助您完成您需要做的那部分。开始一个新项目并尝试上述方法。它适用于我的手机
  • ,我得到了一些东西,我必须从我的代码中删除 sendmsactivity,然后我必须包含你的代码,对吗
  • 您的主要活动是从联系人列表中获取联系人并显示相同的内容。当您勾选复选框并单击按钮时,您将导航到发送消息活动。您会在编辑文本中看到数字。然后您可以在第二个编辑文本中输入短信内容并单击发送按钮,这会将短信内容发送到所选联系人列表
  • 伙计,好的,我会尝试 ping 你
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-07-25
  • 1970-01-01
  • 1970-01-01
  • 2023-03-10
  • 2019-06-03
  • 2014-09-04
  • 2018-08-07
相关资源
最近更新 更多