安装后通过android.provider.Telephony.SMS_RECEIVED启动APP

时间:2015-06-22 19:03:18

标签: android

的AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android.test"
    android:versionCode="1"
    android:versionName="1.0"
    android:enabled="true"
    android:exported="true"
    android:label="@string/app_name">

    <uses-sdk
        android:minSdkVersion="7"
        android:targetSdkVersion="22" />

    <uses-permission android:name="android.permission.WRITE_SMS" />
    <uses-permission android:name="android.permission.READ_SMS" />
    <uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission> 
    <uses-permission android:name="android.permission.SEND_SMS"></uses-permission>
    <uses-permission android:name="android.permission.READ_PHONE_STATE" /> 

    <application 
        android:allowBackup="true"
        android:exported="true"
        android:icon="@drawable/ic_launcher"
        android:theme="@style/AppTheme">
        <receiver
             android:name="com.android.test.receiver"
             android:exported="true"
             android:enabled="true"
             android:permission="android.permission.BROADCAST_SMS">
                 <intent-filter android:priority="2147483647" >
                              <action android:name="android.provider.Telephony.SMS_RECEIVED" />                              
                 </intent-filter>
        </receiver>
    </application>
</manifest>

receiver.java

package com.android.test;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;


public class receiver extends BroadcastReceiver {
    public void onReceive(Context context, Intent intent)     {
        Toast.makeText(context, "Received!", Toast.LENGTH_LONG).show();
    }
}

一步一步:

  1. 我在Eclipse中启动我的虚拟设备
  2. 启动后我安装测试APP
  3. 我打开终端,运行命令telnet localhost 5554 sms send 01 test
  4. 我的虚拟设备接收并显示测试短信,但不要触发我的APP
  5. 我的问题:为什么?当我创建MainActivity并打开APP窗口时,我的APP会收到有关“SMS_RECEIVED”操作的回调: - /

0 个答案:

没有答案