关闭

断网联网或者是解锁完成的广播

标签: android
131人阅读 评论(0) 收藏 举报
分类:



        <receiver android:name="com.kk.dynamic.receiver.MySystemReceiver" >
           <intent-filter android:priority="2147483647" >
                <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
                <action android:name="android.intent.action.USER_PRESENT" />
            </intent-filter>
        </receiver>

-----------

public class MySystemReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
LogManager.ERROR(MySystemReceiver.class, "=action==联网状态==> "+intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false));
Log.d("MySystemReceiver", "=action==东东是==> "+action);
Log.d("MySystemReceiver", "=action==判断是==> "+ action.equals(Intent.ACTION_SCREEN_ON));
Log.d("MySystemReceiver", "=action==判断是==> --------------------------------------");
/**
 * 断网联网或者是解锁完成
 */
if (action.equals(Intent.ACTION_SCREEN_ON)) {
star(context, action);
}
if (intent.getAction().equals("android.net.conn.CONNECTIVITY_CHANGE")) {
ConnectivityManager connectivityManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = connectivityManager.getActiveNetworkInfo();
if (info != null) {
LogManager.ERROR(MySystemReceiver.class, "info.getState()==> "+info.getState());
if (info.getState() == NetworkInfo.State.CONNECTED) {
// showChange.setText("网络变化:网络已连接!");
star(context, action);
} else {
// showChange.setText("网络变化:网络已断开!");
}
} else {
// showChange.setText("网络变化:无网络!");
}
}
}

public void star(Context context,String action){
Log.d("MySystemReceiver", "=action==> 启动服务了--重新执行引导下沉,就是这么任性  "+action);

Intent intent2 = new Intent(context, MyService.class);
context.startService(intent2);
DialogUtils.showToast(context, "广播中后台服务启动...");
}
}


        <receiver android:name="com.kk.dynamic.receiver.MySystemReceiver" >
           <intent-filter android:priority="2147483647" >
                <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
                <action android:name="android.intent.action.USER_PRESENT" />
            </intent-filter>
        </receiver>

-----------

public class MySystemReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
LogManager.ERROR(MySystemReceiver.class, "=action==联网状态==> "+intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false));
Log.d("MySystemReceiver", "=action==东东是==> "+action);
Log.d("MySystemReceiver", "=action==判断是==> "+ action.equals(Intent.ACTION_SCREEN_ON));
Log.d("MySystemReceiver", "=action==判断是==> --------------------------------------");
/**
 * 断网联网或者是解锁完成
 */
if (action.equals(Intent.ACTION_SCREEN_ON)) {
star(context, action);
}
if (intent.getAction().equals("android.net.conn.CONNECTIVITY_CHANGE")) {
ConnectivityManager connectivityManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = connectivityManager.getActiveNetworkInfo();
if (info != null) {
LogManager.ERROR(MySystemReceiver.class, "info.getState()==> "+info.getState());
if (info.getState() == NetworkInfo.State.CONNECTED) {
// showChange.setText("网络变化:网络已连接!");
star(context, action);
} else {
// showChange.setText("网络变化:网络已断开!");
}
} else {
// showChange.setText("网络变化:无网络!");
}
}
}

public void star(Context context,String action){
Log.d("MySystemReceiver", "=action==> 启动服务了--重新执行引导下沉,就是这么任性  "+action);

Intent intent2 = new Intent(context, MyService.class);
context.startService(intent2);
DialogUtils.showToast(context, "广播中后台服务启动...");
}
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:11107次
    • 积分:247
    • 等级:
    • 排名:千里之外
    • 原创:12篇
    • 转载:0篇
    • 译文:2篇
    • 评论:1条
    文章分类
    文章存档