1. 程式人生 > >斷網聯網或者是解鎖完成的廣播

斷網聯網或者是解鎖完成的廣播




        <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, "廣播中後臺服務啟動..."); } }