我正在學習BroadcastReceiver。廣播接收器的顯示Toast
我想顯示Tocard消息SDcard安裝或卸載時。
我跟在SO上提供的幾個例子,並寫下面的代碼。但是,當我安裝/卸載SDCARD(設置 - >卸載SD卡)時,不顯示消息「您好」。
感謝您的任何幫助。
<receiver
android:name="MountReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MEDIA_UNMOUNTED" />
<action android:name="android.intent.action.MEDIA_MOUNTED" />
<data android:scheme="file" />
</intent-filter>
</receiver>
MainActivity.java:
public class MountReceiver extends BroadcastReceiver {
public MountReceiver(){
}
@Override
public void onReceive
(Context context, Intent intent) {
// react to the event
Toast.makeText(MainActivity.this
, "Hello there", Toast.LENGTH_SHORT).show();
}
}
親愛的downvoter,請讓我知道downvote的原因。所以我可以避免這個錯誤謝謝! – user2020