一、什麼是sip?
請移步SIP
二、Android中如何使用sip?
目前比較完善的Sip應用:Sipdroid, Demo: android-sdk-windows\samples\android-9\ SipDemo
三、系統不支持sip?
Android自2.3之後就提供了SIP功能,SIP相關的API在目錄frameworks/base/voip/java/android/net/sip中,存在android.net.sip包中。這裏是解決不支持SIP的整個過程, 要看結果的直接移步文章最後。
在操作SIP之前必須獲得SipManager的實例:
SipManager.newInstance(Context);
這裏,發現有些設備得到的instance爲空。找到SipManager.java中的newInstance方法
/**
* Creates a manager instance. Returns null if SIP API is not supported.
*
* @param context application context for creating the manager object
* @return the manager instance or null if SIP API is not supported
*/
public static SipManager newInstance(Context context) {
return (isApiSupported(context) ? new SipManager(context) : null);
}
/**
* Returns true if the SIP API is supported by the system.
*/
public static boolean isApiSupported(Context context) {
return context.getPackageManager().hasSystemFeature(
PackageManager.FEATURE_SIP);
}
通過調試,發現hasSystemFeature爲空。繼續深入,查看在PackageManager.java的方法hasSystemFeature,盡然是抽象的。
/**
* Check whether the given feature name is one of the available
* features as returned by {@link #getSystemAvailableFeatures()}.
*
* @return Returns true if the devices supports the feature, else
* false.
*/
public abstract boolean hasSystemFeature(String name);
其中這個方法在services/java/com/android/server/pm/ PackageManagerService.java中實現了。
public boolean hasSystemFeature(String name) {
synchronized (mPackages) {
return mAvailableFeatures.containsKey(name);
}
}
在成員mAvailableFeatures中沒有查找到PackageManager.FEATURE_SIP,返回flase。所以無法創建SipManager對象。在PackageManagerService類中,成員變量mAvailableFeatures的值是通過讀取/system/permissions下的xml文件進行設置的。通過查找常量PackageManager.FEATURE_SIP很容易找到兩個和SIP相關的xml文件,在目錄frameworks/base/data/etc/下。根據以往的經驗,這兩個文件既然存在,但/system/permissions目錄下沒有。肯定是沒有拷貝。
繼續查找,發現在device目錄下的Vending.mk文件中。將frameworks/base/data/etc/下的兩個和sip相關的文件拷貝添加進去make即可。
PRODUCT_COPY_FILES += \
device/amlogic/g04ref/tablet_core_hardware.xml:system/etc/permissions/tablet_core_hardware.xml \
frameworks/base/data/etc/android.hardware.camera.front.xml:system/etc/permissions/android.hardware.camera.front.xml \
...
frameworks/base/data/etc/android.software.sip.voip.xml:system/etc/permissions/android.software.sip.voip.xml \
frameworks/base/data/etc/android.software.sip.xml:system/etc/permissions/android.software.sip.xml
如果不編譯系統,直接將兩個文件拷貝到/system/permissions目錄下也是可以的。
原創文章,轉載請註明出處:http://blog.csdn.net/tangcheng_ok