我嘗試過很多(如果不是全部...)接收短信示例,但即使在調用onReceive()之前它也總是失敗。無法在Android上收到短信(過程不好)
的目錄下載:
10-26 20:05:30.990: INFO/System.out(2714): INFO: Received message
10-26 20:05:30.998: INFO/System.out(2714): INFO: Message body: Lmjgk
10-26 20:05:31.021: WARN/ActivityManager(1317): Unable to launch app org.apache.sms/10166 for broadcast Intent { act=android.provider.Telephony.SMS_RECEIVED (has extras) }: process is bad
10-26 20:05:31.021: WARN/ActivityManager(1317): finishReceiver called but none active
當旁邊另一個廣播接收器android.intent.action.PHONE_STATE實施,後來被調用,並正在非常清楚,而短信失敗。
爲了簡化它,我只是創建了hello示例並更新了清單以及SMS BroadcastReceiver的一個文件。
清單:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.byp.sms" android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="9" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".HelloActivity" 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="com.byp.sms.SMSReceiver">
<intent-filter>
<action android:name="android.provider.telephony.SMS_RECEIVED"></action>
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>
<uses-permission android:name="android.permission.READ_SMS" />
</manifest>
的廣播接收器
package com.byp.sms;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class SMSReceiver extends BroadcastReceiver {
private static final String ACTION = "android.provider.Telephony.SMS_RECEIVED";
@Override
public void onReceive(Context context, Intent intent) {
Log.d("SMSReceiver", "onReceive"); // <<=== It does not even get here....
if (intent != null && intent.getAction() != null
&& ACTION.compareToIgnoreCase(intent.getAction()) == 0) {
Object[] pduArray = (Object[]) intent.getExtras().get("pdus");
Log.d("SMSReceiver", "SMSReceived " + pduArray.toString());
}
Log.d("SMSReceiver", "onReceive...Done");
}
}
你好活動:沒有變更所生成的代碼
package com.byp.sms;
import android.app.Activity;
import android.os.Bundle;
public class HelloActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
它沒有幫助,我從設備清理所有相關的應用程序,卸載它,重新啓動設備等,等等。
任何意見或建議將不勝感激!
感謝
我在做類似的事情! http://stackoverflow.com/questions/14452808/sending-and-receiving-mms-in-android – toobsco42