我一直在一個應用程序來響應收到的短信(在你抱怨之前,我知道這已被問很多,但相信我,我不能得到它在工作所有,我試過了幾個小時)。我有我的清單中設置像這樣:Android應用程序沒有響應短信接收器
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.csbctech.notiscreen"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".NotiScreenActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="NotiScreenSmsReceiver" android:process=":remote">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
</intent-filter>
</receiver>
</application>
</manifest>
而且我的接收機類看起來是這樣的:
package com.csbctech.notiscreen;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.CountDownTimer;
import android.os.PowerManager;
import android.util.Log;
public class NotiScreenSmsReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Log.w("NotiScreen", "Got SMS");
}
}
但「NotiScreenSmsReceiver」類不會被調用。我已經嘗試了幾個不同的例子,我不能爲我的生活得到接收器類來調用...我甚至嘗試刪除使用權限,我什至不收到有關沒有權限。什麼可能是錯的?哦,請幫助我,你是我唯一的希望!
我其實在手機上運行GOSMS了。我想知道如果這會導致這個問題......也許現在我會進一步調查......謝謝! –
現在我想到了,如果它不適用於安裝了GOSMS的任何人,那麼這將不太好...有什麼辦法可以解決這個問題嗎?我已經試圖在意圖上使用「優先級」(我將它設置爲999999或者瘋狂的東西,只是爲了試試看),但這並沒有改變任何東西。 –
是的,它們的優先級設置爲2147483647,這是整數可以擁有的最大值!解決方法是使用ContentObserver觀察收件箱,而不是使用廣播。如果你在這個網站上搜索,有很多例子,希望它有幫助!順便說一下,它可能值得在模擬器上進行測試,以檢查GOSMS事實上是否首先導致問題! –