在将短信内容与文本进行比较时,它不起作用。任何人都可以帮我解决这个问题吗?在这里,我想要基于短信内容的 a 和 b 的计数。如果短信内容是a,它会给计数1。如果另一个短信也有内容a,那么计数必须递增到1,即2。下面是我的代码:
package com.example.sms;
import java.util.ArrayList;
import android.app.Activity;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.widget.TextView;
public class Sms extends Activity {
int count=0;
int count1=0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sms);
TextView view1 = (TextView)findViewById(R.id.textview1);
TextView view2 = (TextView)findViewById(R.id.textView2);
Uri uriSMSURI = Uri.parse("content://sms/inbox");
Cursor cur = getContentResolver().query(uriSMSURI, null, null, null,null);
String sms = "";
String data = null;
while (cur.moveToNext()) {
sms =cur.getString(12);
if(sms=="a"){
count=count+1;
view1.setText("a"+count+")");
}
else if(sms=="b"){
count1=count1+1;
view2.setText("a("+count+")");
}
else{
//view1.setText("no data");
}
//data.add(cur.getString(12));
// view1.setText(cur.getString(12));
}
//view1.setText(sms);
//setContentView(view);
}
}