add Networkmanager class
This commit is contained in:
parent
1dd0a7285d
commit
ec30570366
7 changed files with 114 additions and 33 deletions
|
@ -6,7 +6,8 @@
|
|||
<application android:icon="@drawable/linphone2" android:label="@string/app_name" android:debuggable = "true">
|
||||
<activity android:name=".LinphoneActivity"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@android:style/Theme.NoTitleBar">
|
||||
android:theme="@android:style/Theme.NoTitleBar"
|
||||
android:launchMode="singleTask">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
|
@ -21,6 +22,11 @@
|
|||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.CALL" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<data android:scheme="tel" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".ContactPickerActivity">
|
||||
<intent-filter>
|
||||
|
@ -34,7 +40,10 @@
|
|||
</activity>
|
||||
<service android:name=".LinphoneService">
|
||||
</service>
|
||||
</application>
|
||||
<receiver android:name="NetworkManager"><intent-filter><action android:name="android.net.conn.CONNECTIVITY_CHANGE"></action>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
</application>
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
|
||||
<uses-permission android:name="android.permission.RECORD_AUDIO"></uses-permission>
|
||||
|
|
|
@ -29,6 +29,7 @@ import android.app.Activity;
|
|||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.media.AudioManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
@ -200,14 +201,7 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
|
|||
}
|
||||
public void generalState(LinphoneCore lc, GeneralState state) {
|
||||
switch(state) {
|
||||
case GSTATE_CALL_ERROR: {
|
||||
|
||||
Toast toast = Toast.makeText(this
|
||||
,String.format(getString(R.string.call_error),lc.getRemoteAddress())
|
||||
, Toast.LENGTH_LONG);
|
||||
toast.show();
|
||||
break;
|
||||
}
|
||||
case GSTATE_REG_OK: {
|
||||
break;
|
||||
}
|
||||
|
@ -218,23 +212,35 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
|
|||
case GSTATE_CALL_IN_INVITE: {
|
||||
// activate red button
|
||||
mHangup.setEnabled(true);
|
||||
mAudioManager.setSpeakerphoneOn(true);
|
||||
mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
||||
mAudioManager.setRouting(AudioManager.MODE_NORMAL,
|
||||
AudioManager.ROUTE_SPEAKER, AudioManager.ROUTE_ALL);
|
||||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.DONUT) {
|
||||
mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
||||
mAudioManager.setRouting(AudioManager.MODE_NORMAL,
|
||||
AudioManager.ROUTE_SPEAKER, AudioManager.ROUTE_ALL);
|
||||
} else {
|
||||
mAudioManager.setSpeakerphoneOn(true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case GSTATE_CALL_IN_CONNECTED:
|
||||
case GSTATE_CALL_OUT_CONNECTED: {
|
||||
mAudioManager.setSpeakerphoneOn(false);
|
||||
mAudioManager.setMode(AudioManager.MODE_IN_CALL);
|
||||
mAudioManager.setRouting(AudioManager.MODE_NORMAL,
|
||||
AudioManager.ROUTE_EARPIECE, AudioManager.ROUTE_ALL);
|
||||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.DONUT) {
|
||||
mAudioManager.setMode(AudioManager.MODE_IN_CALL);
|
||||
mAudioManager.setRouting(AudioManager.MODE_NORMAL,
|
||||
AudioManager.ROUTE_EARPIECE, AudioManager.ROUTE_ALL);
|
||||
} else {
|
||||
mAudioManager.setSpeakerphoneOn(false);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case GSTATE_CALL_ERROR: {
|
||||
|
||||
Toast toast = Toast.makeText(this
|
||||
,String.format(getString(R.string.call_error),lc.getRemoteAddress())
|
||||
, Toast.LENGTH_LONG);
|
||||
toast.show();
|
||||
}
|
||||
case GSTATE_CALL_END: {
|
||||
mCall.setEnabled(true);
|
||||
mHangup.setEnabled(false);
|
||||
exitCallMode();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -248,4 +254,9 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
|
|||
|
||||
}
|
||||
|
||||
private void exitCallMode() {
|
||||
mCall.setEnabled(true);
|
||||
mHangup.setEnabled(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import android.content.Context;
|
|||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.media.AudioManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
|
@ -95,11 +96,13 @@ public class LinphoneActivity extends TabActivity {
|
|||
super.onDestroy();
|
||||
if (isFinishing()) {
|
||||
//restaure audio settings
|
||||
mAudioManager.setSpeakerphoneOn(true);
|
||||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.DONUT) {
|
||||
mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
||||
mAudioManager.setRouting(AudioManager.MODE_NORMAL,
|
||||
AudioManager.ROUTE_SPEAKER, AudioManager.ROUTE_ALL);
|
||||
|
||||
} else {
|
||||
mAudioManager.setSpeakerphoneOn(false);
|
||||
}
|
||||
Intent intent = new Intent(Intent.ACTION_MAIN);
|
||||
intent.setClass(this, LinphoneService.class);
|
||||
stopService(intent);
|
||||
|
|
|
@ -35,25 +35,16 @@ import org.linphone.core.LinphoneProxyConfig;
|
|||
import org.linphone.core.LinphoneCore.GeneralState;
|
||||
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Service;
|
||||
import android.app.TabActivity;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.media.AudioManager;
|
||||
import android.os.Bundle;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.os.Message;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.TabHost;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class LinphoneService extends Service implements LinphoneCoreListener {
|
||||
static final public String TAG="Linphone";
|
||||
|
@ -91,7 +82,7 @@ public class LinphoneService extends Service implements LinphoneCoreListener {
|
|||
, new File(LINPHONE_RC)
|
||||
, new File(LINPHONE_FACTORY_RC)
|
||||
, null);
|
||||
|
||||
|
||||
initFromConf();
|
||||
|
||||
TimerTask lTask = new TimerTask() {
|
||||
|
@ -249,6 +240,10 @@ public class LinphoneService extends Service implements LinphoneCoreListener {
|
|||
//escape +
|
||||
lDefaultProxyConfig.setDialEscapePlus(true);
|
||||
}
|
||||
//init netwaork state
|
||||
ConnectivityManager lConnectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
mLinphoneCore.setNetworkStateReachable(lConnectivityManager.getActiveNetworkInfo().getState() ==NetworkInfo.State.CONNECTED);
|
||||
|
||||
}catch (LinphoneCoreException e) {
|
||||
throw new LinphoneException(e);
|
||||
}
|
||||
|
|
50
src/org/linphone/NetworkManager.java
Normal file
50
src/org/linphone/NetworkManager.java
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
ContactPickerActivity.java
|
||||
Copyright (C) 2010 Belledonne Communications, Grenoble, France
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
package org.linphone;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
|
||||
public class NetworkManager extends BroadcastReceiver {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
|
||||
NetworkInfo lNetworkInfo = (NetworkInfo) intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
|
||||
Log.i(LinphoneService.TAG, "Network info ["+lNetworkInfo+"]");
|
||||
Boolean lNoConnectivity = intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY,false);
|
||||
//Boolean lIsFailOver = intent.getBooleanExtra(ConnectivityManager.EXTRA_IS_FAILOVER,false);
|
||||
if (lNoConnectivity| ((lNetworkInfo.getState() == NetworkInfo.State.DISCONNECTED) /*&& !lIsFailOver*/)) {
|
||||
LinphoneService.instance().getLinphoneCore().setNetworkStateReachable(false);
|
||||
} else if (lNetworkInfo.getState() == NetworkInfo.State.CONNECTED){
|
||||
LinphoneService.instance().getLinphoneCore().setNetworkStateReachable(true);
|
||||
} else {
|
||||
//unhandle event
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -123,6 +123,15 @@ public interface LinphoneCore {
|
|||
*/
|
||||
public List<LinphoneCallLog> getCallLogs();
|
||||
|
||||
/**
|
||||
* This method is called by the application to notify the Linphone core library when network is reachable.
|
||||
* Calling this method with true trigger Linphone to initiate a registration process for all proxy
|
||||
* configuration with parameter register set to enable.
|
||||
* This method disable the automatic registration mode. It means you must call this method after each network state changes
|
||||
* @param network state
|
||||
*
|
||||
*/
|
||||
public void setNetworkStateReachable(boolean isReachable);
|
||||
/**
|
||||
* destroy linphone core and free all underlying resources
|
||||
*/
|
||||
|
|
|
@ -51,6 +51,7 @@ class LinphoneCoreImpl implements LinphoneCore {
|
|||
private native long getCallLog(long nativePtr,int position);
|
||||
private native int getNumberOfCallLogs(long nativePtr);
|
||||
private native void delete(long nativePtr);
|
||||
private native void setNetworkStateReachable(long nativePtr,boolean isReachable);
|
||||
|
||||
|
||||
LinphoneCoreImpl(LinphoneCoreListener listener, File userConfig,File factoryConfig,Object userdata) throws IOException {
|
||||
|
@ -155,4 +156,7 @@ class LinphoneCoreImpl implements LinphoneCore {
|
|||
throw new RuntimeException("object already destroyed");
|
||||
}
|
||||
}
|
||||
public void setNetworkStateReachable(boolean isReachable) {
|
||||
setNetworkStateReachable(nativePtr,isReachable);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue