未收到广播
相关代码:
package com.example.app31;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends AppCompatActivity {
private ImooocBroadcastReceiver mBroadcastReceiver;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.e("TAG","ggg");
mBroadcastReceiver = new ImooocBroadcastReceiver();
IntentFilter intentFilter=new IntentFilter();
intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
intentFilter.addDataScheme("package");
intentFilter.addAction(Intent.ACTION_BATTERY_LOW);
registerReceiver(mBroadcastReceiver,intentFilter);
}
@Override
protected void onDestroy() {
super.onDestroy();
if (mBroadcastReceiver!=null){
unregisterReceiver(mBroadcastReceiver);
}
}
}
相关代码:
package com.example.app31;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class ImooocBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.e("TAG","re");
if (intent!=null){
String action=intent.getAction();
Log.e("TAG","onReceive: "+action);
}
}
}
10
收起
正在回答 回答被采纳积分+1
2.Android 网络操作与流行框架
- 参与学习 人
- 提交作业 220 份
- 解答问题 1800 个
本阶段是联网及数据处理的必备技能。课程从网络基础知识到线程间协同工作、异步下载处理;从文件存储、到轻量级数据库SQLite的使用;最后利用最流程的第三方框架助你快速开发企业级APP。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星