Changeset 5649 for pjproject/trunk/pjsip-apps/src/swig/java/android/app
- Timestamp:
- Sep 15, 2017 5:32:08 AM (7 years ago)
- Location:
- pjproject/trunk/pjsip-apps/src/swig/java/android/app/src/main/java/org/pjsip/pjsua2/app
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/src/swig/java/android/app/src/main/java/org/pjsip/pjsua2/app/MainActivity.java
r5502 r5649 19 19 package org.pjsip.pjsua2.app; 20 20 21 import android.content.IntentFilter; 21 22 import android.os.Bundle; 22 23 import android.os.Handler; … … 27 28 import android.content.Intent; 28 29 import android.content.pm.ApplicationInfo; 30 import android.content.BroadcastReceiver; 31 import android.content.Context; 29 32 import android.view.LayoutInflater; 30 33 import android.view.Menu; … … 37 40 import android.widget.SimpleAdapter; 38 41 import android.widget.TextView; 42 import android.net.ConnectivityManager; 43 import android.net.NetworkInfo; 39 44 40 45 import java.util.ArrayList; … … 51 56 public static MyAccount account = null; 52 57 public static AccountConfig accCfg = null; 58 public static MyBroadcastReceiver receiver = null; 59 public static IntentFilter intentFilter = null; 53 60 54 61 private ListView buddyListView; … … 66 73 public final static int BUDDY_STATE = 4; 67 74 public final static int CALL_MEDIA_STATE = 5; 75 public final static int CHANGE_NETWORK = 6; 76 } 77 78 private class MyBroadcastReceiver extends BroadcastReceiver { 79 private String conn_name = ""; 80 81 @Override 82 public void onReceive(Context context, Intent intent) { 83 if (isNetworkChange(context)) 84 notifyChangeNetwork(); 85 } 86 87 private boolean isNetworkChange(Context context) { 88 boolean network_changed = false; 89 ConnectivityManager connectivity_mgr = 90 ((ConnectivityManager)context.getSystemService( 91 Context.CONNECTIVITY_SERVICE)); 92 93 NetworkInfo net_info = connectivity_mgr.getActiveNetworkInfo(); 94 if(net_info != null && net_info.isConnectedOrConnecting() && 95 !conn_name.equalsIgnoreCase("")) 96 { 97 String new_con = net_info.getExtraInfo(); 98 if (new_con != null && !new_con.equalsIgnoreCase(conn_name)) 99 network_changed = true; 100 101 conn_name = (new_con == null)?"":new_con; 102 } else { 103 if (conn_name.equalsIgnoreCase("")) 104 conn_name = net_info.getExtraInfo(); 105 } 106 return network_changed; 107 } 68 108 } 69 109 … … 144 184 } 145 185 ); 146 186 if (receiver == null) { 187 receiver = new MyBroadcastReceiver(); 188 intentFilter = new IntentFilter( 189 ConnectivityManager.CONNECTIVITY_ACTION); 190 registerReceiver(receiver, intentFilter); 191 } 147 192 } 148 193 … … 264 309 showCallActivity(); 265 310 311 } else if (m.what == MSG_TYPE.CHANGE_NETWORK) { 312 app.handleNetworkChange(); 266 313 } else { 267 314 … … 577 624 } 578 625 626 public void notifyChangeNetwork() 627 { 628 Message m = Message.obtain(handler, MSG_TYPE.CHANGE_NETWORK, null); 629 m.sendToTarget(); 630 } 631 579 632 /* === end of MyAppObserver ==== */ 580 633 -
pjproject/trunk/pjsip-apps/src/swig/java/android/app/src/main/java/org/pjsip/pjsua2/app/MyApp.java
r5611 r5649 34 34 abstract void notifyCallMediaState(MyCall call); 35 35 abstract void notifyBuddyState(MyBuddy buddy); 36 abstract void notifyChangeNetwork(); 36 37 } 37 38 … … 535 536 } 536 537 538 public void handleNetworkChange() 539 { 540 try{ 541 System.out.println("Network change detected"); 542 IpChangeParam changeParam = new IpChangeParam(); 543 ep.handleIpChange(changeParam); 544 } catch (Exception e) { 545 System.out.println(e); 546 } 547 } 548 537 549 public void deinit() 538 550 {
Note: See TracChangeset
for help on using the changeset viewer.