如何在Android应用程序的后台检测传出的SMS消息?

时间:2011-09-07 10:32:54

标签: android sms detection

如何在后台运行Android应用程序,计算发送的短信数量,另外,确定每个应用程序的详细信息?

2 个答案:

答案 0 :(得分:2)

你可以获取发送消息:

    Uri mSmsinboxQueryUri = Uri.parse("content://sms/sent");
    Cursor cursor1 = getContentResolver().query(mSmsinboxQueryUri,
                new String[] { "_id", "thread_id", "address", "person", "date",
                                "body", "type" }, null, null, null);
    startManagingCursor(cursor1);
    String[] columns = new String[] { "address", "person", "date", "body","type" };
    if (cursor1.getCount() > 0) {
        String count = Integer.toString(cursor1.getCount());
        Log.e("Count",count);
        while (cursor1.moveToNext()){
            String address = cursor1.getString(cursor1.getColumnIndex(columns[0]));
            String name = cursor1.getString(cursor1.getColumnIndex(columns[1]));
            String date = cursor1.getString(cursor1.getColumnIndex(columns[2]));
            String msg = cursor1.getString(cursor1.getColumnIndex(columns[3]));
            String type = cursor1.getString(cursor1.getColumnIndex(columns[4]));
        }
    }

您可以使用计数器来检索最近发送的短信。

请参阅其他有用的链接:

Android: Is there any way to listen outgoing sms?

Listen outgoing SMS or sent box in Android

How to listen/subscribe to Outgoing SMS notifications?

答案 1 :(得分:-3)

使用服务。注册一个服务器的监听器,当通过braodcastreceiver发送短信时接收消息。

在清单中使用它

<receiver android:name="SmsReceiver"> 
        <intent-filter> 
            <action android:name=
                "android.provider.Telephony.SMS_RECEIVED" /> 
        </intent-filter> 
    </receiver>
smsreceiver中的代码

public class SmsReceiver extends BroadcastReceiver

{

    @Override

    public void onReceive(Context context, Intent intent) 

    {

        //here your code



    }



}