安卓读取sms内容,直接写入string里面,为什么读取本人手机的短信内容只有一部分? 本人本人测试的大小是: 182971 (长度)
package com.example.vmplay.readsms; import android.app.Activity; import android.database.Cursor; import android.net.Uri; import java.util.ArrayList; import java.util.List; /** * Created by vmplay on 10/8/2014. */ public class SMSContent { private Activity activity; private Uri uri; List<smsInfo> info; SMSContent(Activity activity,Uri uri) { info=new ArrayList<smsInfo>(); this.activity=activity; this.uri=uri; } public List<smsInfo> getSMSInfo() { String [] projection=new String[]{"_id","address","person","body","date","type"}; Cursor cursor=activity.managedQuery(uri,projection,null,null,"date desc"); int nameColumn=cursor.getColumnIndex("person"); int phoneColumn=cursor.getColumnIndex("address"); int smsbodyColumn=cursor.getColumnIndex("body"); int dateColumn=cursor.getColumnIndex("date"); int typeColumn=cursor.getColumnIndex("type"); if (cursor!=null) { while(cursor.moveToNext()) { smsInfo smsinfo=new smsInfo(); smsinfo.setName(cursor.getString(nameColumn)); smsinfo.setDate(cursor.getString(dateColumn)); smsinfo.setPhone(cursor.getString(phoneColumn)); smsinfo.setBody(cursor.getString(smsbodyColumn)); smsinfo.setType(cursor.getString(typeColumn)); info.add(smsinfo); } cursor.close(); } return info; } }
package com.example.vmplay.readsms; import android.app.Activity; import android.net.Uri; import android.os.Bundle; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.widget.TextView; import java.util.List; public class readSMS extends Activity { /** * 全部的短信 */ public static final String SMS_URI_ALL = "content://sms/"; /** * 收件箱短信 */ public static final String SMS_URI_INBOX = "content://sms/inbox"; /** * 发件箱短信 */ public static final String SMS_URI_SEND = "content://sms/sent"; /** * 草稿箱短信 */ public static final String SMS_URI_DRAFT = "content://sms/draft"; String tag="Rocky_Debug"; private TextView TV_inbox; private String content=new String("a"); private List<smsInfo> myInfo; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_read_sms); TV_inbox=(TextView)findViewById(R.id.smscontent); Uri uri= Uri.parse(SMS_URI_ALL); SMSContent smscontent=new SMSContent(this,uri); myInfo=smscontent.getSMSInfo(); for(int i=0;i<myInfo.size();i++) { smsInfo currentSMS=myInfo.get(i); content=content+currentSMS.getSmsBody()+"\n"; } //TV_inbox.setText(content); Log.d(tag,content); int size=content.length(); Log.d(tag,Integer.toString(size)); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.read_sm, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } }
解决方案:40分
进行短信长度的处理,安卓最长的短信长度为140字节(约为70个汉字),你测试一下看看能否超出最长长度,可以分多次发送