How to create an Android app with only 1 translator?

I am trying to create an Android application consisting of only 1 broadcast broadcaster (and nothing more).

The transmitter should just pick up the broadcast (for example, received sms message, log information and complete). However, I noticed that the broadcast does not hit the receiver unless I indicate that I have the main action, since the following AndroidManifest.xml will show:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapp"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="16" />

<uses-permission android:name="android.permission.RECEIVE_SMS" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <receiver android:name="com.myapp.MyBroadcastReceiver" >
        <intent-filter>
            <action android:name="android.provider.Telephony.SMS_RECEIVED" />
        </intent-filter>
    </receiver>

    <activity
        android:name="com.myapp.MainActivity"
        android:label="@string/activity_main" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

I don’t even need to have an Activity class inside the application. In addition, if I remove either the android.intent.category.LAUNCHER filter or android.intent.action.MAIN in the intent filter, it also does not bother. The behavior is the same on my phone and the emulator running android 4.2

Broadcastreceiver :

public class MyBroadcastReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Toast.makeText(context,intent.getAction(),Toast.LENGTH_SHORT).show();
    }
}

?

+5
2
+6

? ( , , )

0

All Articles