一、什麼是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