Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.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 安卓手机短信接收端口?_Android_Sms_Port - Fatal编程技术网

Android 安卓手机短信接收端口?

Android 安卓手机短信接收端口?,android,sms,port,Android,Sms,Port,我正在开发一个应用程序,接收端口短信。 虽然我还不能收到短信 清单中指定的权限: <uses-permission android:name="android.permission.RECEIVE_SMS" > </uses-permission> 舱单中的广播接收器 <receiver android:name=".BinarySMSReceiver" > <intent-filter android:priority="10" &

我正在开发一个应用程序,接收端口短信。 虽然我还不能收到短信

清单中指定的权限:

 <uses-permission android:name="android.permission.RECEIVE_SMS" >
</uses-permission>
舱单中的广播接收器

<receiver android:name=".BinarySMSReceiver" >
        <intent-filter android:priority="10" >
            <action android:name="android.intent.action.DATA_SMS_RECEIVED" />

            <data
                android:host="*"
                android:port="80"
                android:scheme="sms" />
        </intent-filter>
    </receiver>
 <intent-filter android:priority="1000"> 
广播接收机类

public class BinarySMSReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
    Bundle bundle = intent.getExtras();
    SmsMessage[] msgs = null;

    if (null != bundle) {
        // String info = "SMS from ";
        String info = "SMS from ";
        String sender = "";
        String sms = "";
        // String info = "";

        Object[] pdus = (Object[]) bundle.get("pdus");

        msgs = new SmsMessage[pdus.length];
        byte[] data = null;

        for (int i = 0; i < msgs.length; i++) {
            msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
            sender += msgs[i].getOriginatingAddress();
            // info += "\n*****BINARY MESSAGE*****\n";
            info += msgs[i].getOriginatingAddress() + "\n";

            data = msgs[i].getUserData();

            for (int index = 0; index < data.length; ++index) {
                info += Character.toString((char) data[index]);
                sms += Character.toString((char) data[index]);
            }
        }
        DatabaseHandler db = new DatabaseHandler(context);

        db.addSMS(new SMS(sender, sms));

        Intent i = new Intent(context, SMSListActivity.class);
        i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
                i, Intent.FLAG_ACTIVITY_NEW_TASK);

        NotificationManager mNotificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                context)
                .setSmallIcon(R.drawable.ic_launcher)
                .setContentTitle("PORT SMS")
                // Vibration
                .setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 })
                // LED
                .setLights(Color.RED, 3000, 3000)
                .setSound(Settings.System.DEFAULT_NOTIFICATION_URI)
                .setWhen(System.currentTimeMillis())
                .setStyle(new NotificationCompat.BigTextStyle()

                .bigText(info)).setContentText(info);
        mBuilder.setContentIntent(contentIntent);
        mNotificationManager.notify(2, mBuilder.build());
        Log.e("msgg   ", info);
        // t.setText(info);
        Toast.makeText(context, info, Toast.LENGTH_SHORT).show();
    }
}
  }

我在清单中遗漏了什么吗?

增加清单中的优先级

<receiver android:name=".BinarySMSReceiver" >
        <intent-filter android:priority="10" >
            <action android:name="android.intent.action.DATA_SMS_RECEIVED" />

            <data
                android:host="*"
                android:port="80"
                android:scheme="sms" />
        </intent-filter>
    </receiver>
 <intent-filter android:priority="1000"> 

之后,如果您遇到任何问题,请点击链接

,该链接将介绍文本短信息,而不是端口短信息。端口SMS接收到应用程序中指定的特定端口,该端口不在收件箱中。您在端口80上监听什么?也就是说,您是否从其他应用程序发送测试短信?如果是这样,您确定它们发送正确吗?我正在端口80上发送测试sms表单api。您的接收器应用程序中是否有活动?收到消息后,我会显示通知。点击通知后,我会将用户移动到“活动”中。在安装后至少启动一次应用程序之前,应用程序处于停止状态,并且您的接收器将无法工作。运行您的活动一次,然后测试您的短信。这是假设您运行的是Android>3.0版本,但大多数人都是这样。