android 短信读取程序, 为什么string的长度(短信内容)只有一小部分

量化分析 量化分析 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
安卓读取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);
}
}

...全文

相关推荐

评论 4
收藏 已收藏
分享
返回顶部
量化分析
Android 80,490 成员 91,371 内容