我已经弄明白了如何发送和接收短信.要发送短信,我必须调用该类的sendTextMessage()和sendMultipartTextMessage()方法SmsManager.要接收SMS消息,我必须在AndroidMainfest.xml文件中注册接收器.然后我不得不重写onReceive()方法BroadcastReceiver.我在下面列举了一些例子.
MainActivity.java
public class MainActivity extends Activity {
    private static String SENT = "SMS_SENT";
    private static String DELIVERED = "SMS_DELIVERED";
    private static int MAX_SMS_MESSAGE_LENGTH = 160;
    // ---sends an SMS message to another device---
    public static void sendSMS(String phoneNumber, String message) {
        PendingIntent piSent = PendingIntent.getBroadcast(mContext, 0, new Intent(SENT), 0);
        PendingIntent piDelivered = PendingIntent.getBroadcast(mContext, 0,new Intent(DELIVERED), 0);
        SmsManager smsManager = SmsManager.getDefault();
        int length = message.length();          
        if(length > MAX_SMS_MESSAGE_LENGTH) …我一直试图让这个程序工作,但到目前为止没有运气.我无法找到我做错的地方.我不确定代码或调试是否有问题.
我正在尝试收到新短信到达时的通知.
这是我的计划:
package Technicaljar.SMSBroadcastReceiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.util.Log;
public class SMSBroadcastReceiver extends BroadcastReceiver {
        private static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
        private static final String TAG = "SMSBroadcastReceiver";
        @Override
        public void onReceive(Context context, Intent intent) {
             Log.i(TAG, "Intent recieved: " + intent.getAction());
                if (intent.getAction() == SMS_RECEIVED) {
                    Bundle bundle = intent.getExtras();
                    if (bundle != null) {
                        Object[] pdus = (Object[])bundle.get("pdus");
                        final SmsMessage[] messages = new SmsMessage[pdus.length];
                        for (int i …BroadcastReceiver中的AlertDialog?可以吗?我正在开发一个应用程序,如果我收到短信,会弹出一个对话框.我试图在BroadcaseReceiver中编写代码.但我不能使用这行代码AlertDialog.Builder builder = new AlertDialog.Builder(this);.有人可以帮我提示一下!
public class SMSPopUpReceiver extends BroadcastReceiver {
    private static final String LOG_TAG = "SMSReceiver";
    public static final int NOTIFICATION_ID_RECEIVED = 0x1221;
    static final String ACTION = "android.provider.Telephony.SMS_RECEIVED";
    public void onReceive(Context context, Intent intent) {
        Log.i(LOG_TAG, "onReceive");
        if (intent.getAction().equals(SMSPopUpReceiver.ACTION)) {
            StringBuilder sb = new StringBuilder();
            Bundle bundle = intent.getExtras();
            if (bundle != null) {
            Object[] pdus = (Object[]) bundle.get("pdus");
            for (Object pdu : pdus){
                    SmsMessage messages =
            SmsMessage.createFromPdu((byte[]) pdu);
            sb.append("Received SMS\nFrom: ");
            sb.append(messages.getDisplayOriginatingAddress());
            sb.append("\n----Message----\n");
            sb.append( …我已经实现了自定义网址方案.如果我在html中的标签中使用该方案,它工作正常,但我想以文本/纯SMS消息发送它.该方案不会被任何标准应用程序解析.有没有什么方法可以说服应用程序将我的新方案解析为纯文本链接?
该计划是"appname:// go/something"
菲尔
我希望能够从收到的短信中提取文本.我不确定是否应该使用内容提供商,或者短信息包含在广播接收者收到的意图中.
我有一个等待短信的广播接收器,并希望检查收到的消息的内容.
谢谢.
我迫切希望找到解决方案,所以我请求帮助!我是一名新的法国程序员.我的目标是创建一个能够显示SMS的小部件.我的问题是,我不知道如何创建一个光标,在内容中选择第一条短信://短信/收件箱请原谅我的英文不好,希望你能理解我的意思.谢谢您的回答.这是我的代码:
package sfeir.monwidget;
import android.R.string;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.net.Uri;
import android.widget.RemoteViews;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.widget.ArrayAdapter;   
public class MonWidget extends AppWidgetProvider {
 public void onUpdate(Context context, AppWidgetManager appWidgetManager,
            int[] appWidgetIds) {
     Uri uri = Uri.parse("content://sms/inbox");
    // returns all the results.
    Cursor c= getContentResolver().query(uri, null, null ,null,null); 
    // called by the Activity.
    startManagingCursor(c);
    String body = null;
    String number = null;
    if(c.moveToFirst()) { // move cursor to first row
       // retrieves the …我是android新手,我正在做一些可能使用多线程的应用程序.例如,假设有两个线程,应用程序线程可以执行如下操作;
线程1即使整个应用程序在前台线程上运行,也应该一直运行,监听特定的短信; 想象一下,当这条消息发送到手机时被拦截的短信是"3456",然后线程1将被暂停,线程2将被激活:
线程2当线程被激活时,它将使用gps跟踪手机的位置,并将使用smsManager的实例发送回手机的坐标(log,lat),或者即使可能的谷歌地图回到发送的手机消息"3456"然后线程1将被激活:
**如何实现这一点?