我有一个接收消息的广播接收器类。我存储消息和不同的变量。 并在用户面前以吐司方式打印。 问题是我想在另一个函数中传递消息字符串,当我运行应用程序时,我想从第二个函数输出结果。
我的代码是
package com.example.broadcastreceiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.telephony.SmsMessage;
import android.util.Log;
import android.widget.Toast;
public class IncomingSms extends BroadcastReceiver {
// Get the object of SmsManager
final SmsManager sms = SmsManager.getDefault();
public void onReceive(Context context, Intent intent) {
// Retrieves a map of extended data from the intent.
final Bundle bundle = intent.getExtras();
try {
if (bundle != null) {
final Object[] pdusObj = (Object[]) bundle.get("pdus");
for (int i = 0; i < pdusObj.length; i++) {
SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[i]);
String phoneNumber = currentMessage.getDisplayOriginatingAddress();
String senderNum = phoneNumber;
String message = currentMessage.getDisplayMessageBody();
System.out.println(phoneNumber);
System.out.println(message);
Log.i("SmsReceiver", "senderNum: "+ senderNum + "; message: " + message);
int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(context, "senderNum: "+ senderNum + ", message: " + message, duration);
toast.show();
} // end for loop
} // bundle is null
} catch (Exception e) {
Log.e("SmsReceiver", "Exception smsReceiver" +e);
}
}
}
我的活动课程是 -
package com.example.broadcastreceiver;
import com.androidexample.broadcastreceiver.R;
import android.os.Bundle;
import android.app.Activity;
public class BroadcastNewSms extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.androidexample_broadcast_newsms);
}
}
我的第二个功能是在这里我希望传递消息并获得输出
String type="CEXAD";
String caseno="139";
String year="2013";
String url = "http://"url"?type=" + type + "&num=" + caseno + "&year=" + year;
public void print(String type,String caseno,String year,String url) throws IOException{
Document doc = Jsoup.connect(url).timeout(20*1000).get();
Element pending = doc.select("table td:eq(0)").first();
Element nextDate = doc.select("table td:eq(0)").get(10);
Element date = doc.select("table td:eq(1)").last();
int nex=doc.select("table td:eq(0)").size();
}