我對Android編程頗爲陌生,我正在盡我所能理解本教程。我已經從this link下載了示例代碼。如何在AndroidManifest.xml中添加代碼
現在我想集成這個thread的代碼。這裏說
的代碼是「在你的AndroidManifest.xml中聲明短信接收器」:
<receiver android:name="mypackage.SMSReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
</intent-filter>
</receiver>
<uses-permission android:name="android.permission.RECEIVE_SMS" />
下面是從樣本文件中的現有代碼,我的AndroidManifest.xml下下載:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.smsTest"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".SMSTest"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.SEND_SMS">
</uses-permission>
<uses-permission android:name="android.permission.RECEIVE_SMS">
</uses-permission>
</manifest>
現在我的問題是將代碼(上面的第一個代碼)添加到AndroidManifest.xml的位置。
我試圖改變這一行:
<action android:name="android.intent.action.MAIN" />
與此:
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
沒有運氣。
任何幫助表示讚賞。
首先,XML不是代碼,而是數據。其次,谷歌10秒。 http://www.vogella.com/articles/AndroidBroadcastReceiver/article.html – Simon 2013-04-06 20:40:43