Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Android中监视传入的SMS消息_Android_Sms - Fatal编程技术网

在Android中监视传入的SMS消息

在Android中监视传入的SMS消息,android,sms,Android,Sms,我有这个程序,将试图监测传入的短信。但是,当我试图在模拟器中运行我的程序并尝试发送SMS消息时,它起作用了。但是当我在手机上安装程序时,它就不工作了 有什么问题 我也想在后端运行这个程序。怎么做 顺便说一句,下面是这个示例应用程序的全部代码 谢谢 RJ 我将用您提供的一点细节来假设它在模拟器上工作而不是在您的实际手机上工作的原因;可能是另一个冲突的应用程序在消息广播到您的应用程序之前拦截消息 尝试将android:priority=“1000”添加到应用程序清单中接收者的意向过滤器中 (一千是

我有这个程序,将试图监测传入的短信。但是,当我试图在模拟器中运行我的程序并尝试发送SMS消息时,它起作用了。但是当我在手机上安装程序时,它就不工作了

有什么问题

我也想在后端运行这个程序。怎么做

顺便说一句,下面是这个示例应用程序的全部代码

谢谢

RJ



我将用您提供的一点细节来假设它在模拟器上工作而不是在您的实际手机上工作的原因;可能是另一个冲突的应用程序在消息广播到您的应用程序之前拦截消息

尝试将android:priority=“1000”添加到应用程序清单中接收者的意向过滤器中 (一千是你认为必要的数字,如果需要的话可以更高)


试试这个:

<receiver android:name=".MySMSMonitor"
              android:permission="android.permission.BROADCAST_SMS">

      <intent-filter android:priority="2">
        <action android:name="android.provider.Telephony.SMS_RECEIVED" />
      </intent-filter>
    </receiver>

我会坚持让您使用
ContentObserver
并注册
content://sms
Uri并使用

cusor.getString(cusor.getColumnIndex("type")); // 1 = SMS Received 
                                               // 2 =  SMS Sent

此外,您还可以从获取的光标轻松获取所需的数据。是一个同样的博客。

如果说不工作没有帮助,请指出错误。是撞车吗?或者某些功能不起作用,它不会崩溃。。onReceive()没有被调用来获得祝酒词,就在以下行之后:public void onReceive(上下文,意图){,在您设置条件之前。您使用什么“发送”和短信到手机?您是否通过股票消息应用程序收到短信通知?尽管此答案非常适合监控短信(过去/现在/未来),谷歌已间接声明查询ContentProvider
content://sms
可能会在较新的设备上出现故障,因为它不是SDK的一部分。现在很明显,我怀疑任何制造商或sms应用程序是否会偏离向后兼容性,但你永远不会知道。我仍然担心在lea让广播接收器工作未来项目的st。
import android.app.Activity; 
import android.os.Bundle; 
import android.telephony.SmsManager; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.Toast;

public class TelephonyDemo extends Activity
{
    @Override 
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main); 
        Button sendBtn = (Button)findViewById(R.id.sendSmsBtn);

        sendBtn.setOnClickListener(new OnClickListener(){
            @Override public void onClick(View view) {
            EditText addrTxt = (EditText)TelephonyDemo.this.findViewById(R.id.addrEditText);

            EditText msgTxt = (EditText)TelephonyDemo.this.findViewById(R.id.msgEditText);
            try { 
                sendSmsMessage(
                        addrTxt.getText().toString(),msgTxt.getText().toString()); 
                Toast.makeText(TelephonyDemo.this, "SMS Sent",
                        Toast.LENGTH_LONG).show(); 
            } catch (Exception e) {
                Toast.makeText(TelephonyDemo.this, "Failed to send SMS", Toast.LENGTH_LONG).show();
                e.printStackTrace();
            }
        }});
    }

    @Override 
    protected void onDestroy() {
        super.onDestroy();
    }

    private void sendSmsMessage(String address,String message)throws Exception {
        SmsManager smsMgr = SmsManager.getDefault(); 
        smsMgr.sendTextMessage(address, null, message, null, null);
    }
}
<intent-filter android:priority="1000" >
            <action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
<receiver android:name=".MySMSMonitor"
              android:permission="android.permission.BROADCAST_SMS">

      <intent-filter android:priority="2">
        <action android:name="android.provider.Telephony.SMS_RECEIVED" />
      </intent-filter>
    </receiver>
cusor.getString(cusor.getColumnIndex("type")); // 1 = SMS Received 
                                               // 2 =  SMS Sent