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




        <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, "广播中后台服务启动...");
}
}

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/QQ1375235976/article/details/51543462
文章标签: android
个人分类: Android
上一篇Android注册广播
下一篇Assets文件夹
想对作者说点什么? 我来说一句

按键精灵的自动联网断网脚本

2009年04月25日 844B 下载

没有更多推荐了,返回首页

关闭
关闭