我想编写代码来接收短信,因为我已经做了一个 BroadcastReceiver 活动,甚至做了服务。但是,我的服务没有启动。我在 Service 的 onStart 方法上显示了 toast。
这是我的服务类:
public class Bg_sms_verify_service extends Service {
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate() {
Toast.makeText(this, "The new Service was Created", Toast.LENGTH_LONG).show();
}
@Override
public void onStart(Intent intent, int startId) {
// For time consuming an long tasks you can launch a new thread here...
Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show();
/* BroadcastReceiver_file bc = new BroadcastReceiver_file();
bc.onReceive(this, intent);*/
}
}
Android 清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.anti_theftapplication"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.SEND_SMS"></uses-permission>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.anti_theftapplication.MainActivity"
android:label="@string/app_name" >
</activity>
<activity
android:name="com.example.anti_theftapplication.ListOfOptions"
android:label="@string/title_activity_list_of_options" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.anti_theftapplication.SMS_Send"
android:label="@string/title_activity_sms__send" >
</activity>
<receiver android:name="com.androidexample.anti_theftapplication.BroadcastReceiver_file" android:enabled="true" android:exported="false">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
</application>
</manifest>
我不知道出了什么问题。请帮助您的建议。