我刚刚编写了这个小应用程序,每次更改飞行模式都会显示一个小的Toast。它不起作用
package com.example.android.broadcastreceiverexample;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;
import static android.widget.Toast.*;
public class MyReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent){
makeText(context, "Intent detected", LENGTH_LONG).show();
}
}
这是清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.android.broadcastreceiverexample">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".MyReceiver" android:exported="true">
<intent-filter tools:ignore="ExtraText">
<action android:name="android.intent.action.AIRPLANE_MODE></action>
</intent-filter>
</receiver>
</application>
</manifest>
在概念上还是在代码中我缺少某些东西吗?