⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmppdatamessagereceiver.java

📁 Google s android SDK
💻 JAVA
字号:
/*  * Copyright (C) 2007 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * *      http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package com.google.android.samples.app;import android.content.IntentReceiver;import android.content.Context;import android.content.Intent;import android.app.NotificationManager;import android.util.Log;import android.os.Bundle;import java.util.Map;import java.util.Iterator;/** * <p>Example of using the XmppService{@link com.google.android.xmppService.IXmppService} to * receive peer to peer data messages. * This demonstrates how to use the XmppService to receive data to/from another Android device.</p><h4>Demo</h4>App/Service/Xmpp Data Message Receiver<h4>Source files</h4><table class="LinkTable">        <tr>            <td class="LinkColumn">src/com/google/android/samples/app/XmppDataMessageReceiver.java</td>            <td class="DescrColumn">The XmppService data message receiver</td>        </tr>        <tr>            <td class="LinkColumn">src/com/google/android/samples/app/XmppDataMessageSender.java</td>            <td class="DescrColumn">The XmppService data message Sender</td>        </tr></table> */public class XmppDataMessageReceiver extends IntentReceiver {    private static final String LOG_TAG = "XmppSrvSample";    /* package */ static final String ACTION =            "com.google.android.samples.app.XmppDataMessageReceiver.ACTION_DATA_MESSAGE";    public void onReceiveIntent(Context context, Intent intent) {        if (intent.getAction().equals(ACTION)) {            StringBuilder buf = new StringBuilder();            buf.append("Got data message, action=");            buf.append(ACTION);            Bundle bundle = intent.getExtras();            if (bundle != null) {                if (bundle.getString("poke") != null) {                    appendData(buf, "poke", bundle.getString("poke"));                }                if (bundle.getString("question") != null) {                    appendData(buf, "question", bundle.getString("question"));                }            }            Log.i(LOG_TAG, "[XmppDataMessageReceiver] onReceiveIntent: " + buf);            NotificationManager nm = (NotificationManager)context.getSystemService(                    Context.NOTIFICATION_SERVICE);            nm.notifyWithText(123, buf.toString(),                    NotificationManager.LENGTH_LONG, null);        }    }    private void appendData(StringBuilder buf, String key, String value) {        buf.append(", ");        buf.append(key);        buf.append('=');        buf.append(value);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -