简体   繁体   English

如何通过sip在android中发送短信

[英]How to send text message in android via sip

我正在开发一个Android应用程序,我希望使用sip / xmpp(会话启动协议)发送文本消息,任何人都可以给我代码,以及任何关于它在任何免费sip提供程序上开发和测试的指南。

Update having re-read 重新阅读更新
Sorry, I failed to realise that the question related only to text messaging. 对不起,我没有意识到这个问题只与短信有关。 SIP itself doesn't support text messaging, SIMPLE or MSRP extensions enable that. SIP本身不支持短信,SIMPLE或MSRP扩展支持。 You need to find a stack that you are happy working with, here is one example Doubango and their demo product IMSDroid but Google 'Android MSRP' for plenty of other options. 你需要找到一个你很满意的堆栈,这里有一个例子Doubango和他们的演示产品IMSDroid,但谷歌的“Android MSRP”有很多其他选择。 I still don't know anything about XMPP,but check out this thread for a great list of libraries and uses. 我仍然对XMPP一无所知,但请查看此主题以获取一系列库和用途。
End update 结束更新

What have you tried so far? 你都尝试了些什么? For the SIP (voice) part of your question here is the documentation on the Android Developers site with all you need to know and here is a free SIP provider: Getonsip . 对于您的问题的SIP(语音)部分,这里是Android开发者网站上的文档,您需要知道所有这些,这里是免费的SIP提供商: Getonsip

Reduced code sample, largely lifted from Android developer site. 代码示例减少,大部分都是从Android开发者网站上提取的。

Essentially you need to make sure minSDK is set to 9 as the SIP library was not added until 2.3. 基本上你需要确保minSDK设置为9,因为直到2.3才添加SIP库。 Add the services to your manifest: 将服务添加到清单:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.USE_SIP" />

Optionally add the uses-feature voip directive if you want your app to not install on devices where it will not work. 如果您希望应用程序不安装在无法运行的设备上,请选择添加uses-feature voip指令。

<uses-feature android:name="android.hardware.sip.voip" />

Create a SipManager: 创建一个SipManager:

android.net.sip.SipManager manager = SipManager.newInstance(this);

Create a profile with which to make/receive calls through your provider: 创建一个配置文件,通过您的提供商拨打/接听电话:

android.net.sip.SipProfile.Builder builder = new SipProfile.Builder(username, domain);
builder.setPassword(password);
android.net.sip.SipProfile sipProfile = builder.build();

If all you care about is making calls: 如果你关心的只是打电话:

manager.open(profile);

To make a call you u work with a listener: 要拨打电话,您需要与听众合作:

SipAudioCall.Listener listener = new SipAudioCall.Listener() {

    @Override
    public void onCallEstablished(SipAudioCall call) {
        call.startAudio();
        call.setSpeakerMode(true);
        call.toggleMute();
        ...
    }

    @Override
    public void onCallEnded(SipAudioCall call) {
        // Do something.
    }
};

Now, as long as you have the SIP address of your peer you can use: 现在,只要您拥有对等方的SIP地址,您就可以使用:

SipProfile friendProfile = ...;
manager.makeAudioCall(sipProfile.getUriString(), friendAddress, listener, 30);

That should get you started. 这应该让你开始。 Unfortunately I have no experience with XMPP. 不幸的是,我没有使用XMPP的经验。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM