ContextWrapper ?|? Android Developers
android.content.ContextWrapper
- Public methods
- public Intent registerReceiver (BroadcastReceiver receiver, IntentFilter filter)
- public Intent registerReceiver (BroadcastReceiver receiver, IntentFilter filter, int flags)
- public Intent registerReceiver (BroadcastReceiver receiver, IntentFilter filter, String broadcastPermission, Handler scheduler, int flags)
- public Intent registerReceiver (BroadcastReceiver receiver, IntentFilter filter, String broadcastPermission, Handler scheduler)
示例代码
MainActivity.java
package com.example.learn_recevier_context_registered;
import androidx.appcompat.app.AppCompatActivity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AirplanModeReceiver airplanModeReceiver = new AirplanModeReceiver();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("android.intent.action.AIRPLANE_MODE");
registerReceiver(airplanModeReceiver, intentFilter);
}
class AirplanModeReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "飞行模式", Toast.LENGTH_SHORT).show();
}
}
}
|