通过百度开始使用通知中心Get started with Notification Hubs using Baidu

Important

本教程已弃用。This tutorial is deprecated.

百度云推送是一种中国云服务,可用于将推送通知发送到移动设备。Baidu cloud push is a Chinese cloud service that you can use to send push notifications to mobile devices.

由于 Google Play 和 FCM (Firebase Cloud Messaging) 在中国不可用,必须使用其他的应用商店和推送服务。As Google Play and FCM (Firebase Cloud Messaging) are not available in China, it is necessary to use different app stores and push services. 百度就是其中的一个,也是通知中心目前所使用的。Baidu is one of them, and the one currently used by Notification Hub.

先决条件Prerequisites

本教程需要:This tutorial requires:

Note

要完成本教程,必须有一个有效的 Azure 帐户。To complete this tutorial, you must have an active Azure account. 如果没有帐户,可以创建一个试用帐户,只需几分钟即可完成。If you don't have an account, you can create a trial account in just a couple of minutes. 有关详细信息,请参阅 Azure 1 元试用For details, see Azure 1rmb-trial.

创建百度帐户Create a Baidu account

要使用百度,必须有一个百度帐户。To use Baidu, you must have a Baidu account. 如果已有帐户,请登录 百度门户,并跳到下一步。If you already have one, log in to the Baidu portal and skip to the next step. 否则请参阅以下说明创建百度帐户。Otherwise, see the following instructions on how to create a Baidu account.

  1. 转到百度门户并单击“登录”链接 。Go to the Baidu portal and click the 登录 (Login) link. 单击“立即注册”(Register Now) 以启动帐户注册过程。 Click 立即注册 (Register Now) to start the account registration process.

    百度注册

  2. 输入所需的详细信息(电话/电子邮件地址、密码和验证码),并单击“注册”(Signup)。 Enter the required details—phone/email address, password, and verification code—and click 注册 (Signup).

    百度注册输入

  3. 系统会将一封电子邮件发送到输入的电子邮件地址,该邮件包含一个用于激活百度帐户的链接。You are sent an email to the email address that you entered with a link to activate your Baidu account.

    百度注册确认

  4. 登录到用户的电子邮件帐户,打开百度激活邮件,并单击激活链接以激活用户的百度帐号。Log in to your email account, open the Baidu activation mail, and click the activation link to activate your Baidu account.

    百度激活电子邮件

有已激活的百度帐户后,请登录 百度门户Once you have an activated Baidu account, log in to the Baidu portal.

创建百度云推送项目Create a Baidu cloud push project

在创建百度云推送项目时,将收到应用程序 ID、API 密钥和密钥。When you create a Baidu cloud push project, you receive your app ID, API key, and secret key.

  1. 登录到百度门户后,请单击“更多>>” 。Once you have logged in to the Baidu portal, click 更多>> (more).

    注册 - 更多内容

  2. 向下滚动“站长与开发者服务”(Webmaster and Developer Services) 部分并单击“百度云推送”(Baidu Cloud Push)。 Scroll down in the 站长与开发者服务 (Webmaster and Developer Services) section and click 百度云推送 (Baidu Cloud Push).

    百度开放云平台

  3. 在下一页的右上角单击“登录” (Login)。 On the next page, click 登录 (Login) on the top-right corner.

    百度登录

  4. 然后,单击该页上的“创建应用”(Create Application)。 Then, click 创建应用 (Create Application) on this page.

    百度“创建应用”

  5. 在下一页上单击“创建新应用”(Create New Application)。 On the next page, click 创建新应用 (Create New Application).

    百度“创建新应用”

  6. 输入应用程序名称,并单击“创建”(Create)。 Enter an application name and click 创建 (Create).

  7. 成功创建百度云推送项目后,会显示一个页面,其中包含“AppID”、“API 密钥”和“密钥”。 Upon successful creation of a Baidu cloud push project, you see a page with AppID, API Key, and Secret Key. 请记下 API 密钥和密钥,因为稍后将要用到。Make a note of the API key and secret key, which we use later.

    百度“推送机密”

  8. 通过单击左侧窗格中的“创建通知”(Create Notification) 来配置推送通知项目。 Configure the project for push notifications by clicking 创建通知 (Create Notification) on the left pane.

配置新通知中心Configure a new notification hub

  1. 登录到 Azure 门户Sign in to the Azure portal.

  2. 在左侧菜单上选择“所有服务”,然后在“移动”部分中选择“通知中心”。Select All services on the left menu, and select Notification Hubs in the Mobile section. 选择服务名称旁边的星星 (*) 以将其添加到左侧菜单上的“收藏夹”部分。Select star (*) next to the service name to add it to the FAVORITES section on the left menu. 在将“通知中心”添加到“收藏夹”之后,在菜单上选择它。After Notification Hubs is added to FAVORITES, select it on the left menu.

    Azure 门户 - 选择“通知中心”

  3. 在“通知中心”页面上,在工具栏上选择“添加”。On the Notification Hubs page, select Add on the toolbar.

    通知中心 -“添加”工具栏按钮

  4. 在“通知中心”页面上,执行以下步骤:On the Notification Hub page, do the following steps:

    1. 为通知中心指定一个名称。Specify a name for the notification hub.

    2. 为命名空间指定一个名称。Specify a name for the namespace. 命名空间包含一个或多个中心。A namespace contains one or more hubs.

    3. 选择要在其中创建通知中心的位置。Select a location in which you want to create the notification hub.

    4. 选择一个现有资源组,或者为新资源组输入一个名称。Select an existing resource group or enter a name for the new resource group.

    5. 选择“创建” 。Select Create.

      Azure 门户 - 设置通知中心属性

  5. 选择“通知”(钟形图标),然后选择“转到资源”。Select Notifications (Bell icon), and select Go to resource. 还可以刷新“通知中心”页中的列表,然后选择通知中心。You can also refresh the list in the Notification Hubs page, and select your notification hub.

    Azure 门户 - 通知 -> 转到资源

  6. 从列表中选择“访问策略”。Select Access Policies from the list. 记下向你提供的两个连接字符串。Note the two connection strings that are available to you. 稍后在处理推送通知时需要它们。You need them to handle push notifications later.

    Important

    在应用程序中使用 DefaultFullSharedAccessSignature。Do NOT use the DefaultFullSharedAccessSignature in your application. 这只能在后端使用。This is meant to be used in your back-end only.

    Azure 门户 - 通知中心连接字符串

  6.  6. 在通知中心选择“通知服务”,然后选择“百度(Android China)”。 In your notification hub, select Notification Services and then Baidu (Android China).

    Azure 通知中心 - 百度

  7.  7. 向下滚动到百度通知设置部分。Scroll down to the Baidu notification settings section. 在百度云推送项目中,输入从百度控制台获得的 API 密钥和密钥。Enter the API key and secret key that you obtained from the Baidu console, in the Baidu cloud push project. 然后单击“保存”。Then click Save.

    Azure 通知中心 - 百度机密

通知中心现在已配置为使用百度。Your notification hub is now configured to work with Baidu. 此外还有连接字符串,用于注册发送和接收推送通知的应用。You also have the connection strings to register your app to both send and receive push notifications.

记下“访问连接信息”窗口中的 DefaultListenSharedAccessSignatureDefaultFullSharedAccessSignatureMake a note of the DefaultListenSharedAccessSignature and DefaultFullSharedAccessSignature from the Access connection information window.

将应用连接到通知中心Connect your app to the notification hub

  1. 在 Android Studio 中创建新的 Android 项目(“文件”>“新建”>“新建项目”)。In Android Studio, create a new Android project (File > New > New Project).

    Azure 通知中心 - 百度“新建项目”

  2. 输入应用程序名称,并确保将要求的最低 SDK 版本设为“API 16:Android 4.1”。Enter an Application Name and ensure that the Minimum Required SDK version is set to API 16: Android 4.1. 另请确保应用包名与百度云推送门户中的相同Also please make sure your package name (应用包名) is the same as in the Baidu Cloud Push Portal

    Azure 通知中心 - 百度 Min SDK1 Azure 通知中心 - 百度 Min SDK2Azure Notification Hubs - Baidu Min SDK1 Azure Notification Hubs - Baidu Min SDK2

  3. 单击“下一步”,并继续执行向导,直到显示“创建活动”窗口。Click Next and continue following the wizard until the Create Activity window appears. 确保选中了“空活动”,最后选择“完成”以创建新的 Android 应用程序。Make sure that Empty Activity is selected, and finally select Finish to create a new Android Application.

    Azure 通知中心 - 百度“添加活动”

  4. 确保“项目生成目标”已正确设置。Make sure that the Project Build Target is set correctly.

  5. 然后添加 Azure 通知中心库。Then add Azure Notification Hubs libraries. 在应用的 Build.Gradle 文件中,在 dependencies 节添加以下行。In the Build.Gradle file for the app, add the following lines in the dependencies section.

    implementation 'com.microsoft.azure:notification-hubs-android-sdk:0.6@aar'
    implementation 'com.microsoft.azure:azure-notifications-handler:1.0.1@aar'
    

    在 dependencies 节的后面添加以下存储库。Add the following repository after the dependencies section.

    repositories {
        maven {
            url "https://dl.bintray.com/microsoftazuremobile/SDK"
        }
    }
    

    为了避免列表冲突,请在项目的 Manifest.xml 文件中添加以下代码:To avoid the List conflict, add the following code in the project's Manifest.xml file:

    <manifest package="YOUR.PACKAGE.NAME"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android">
    

    然后在 <application/> 标记中执行以下操作:and in the <application/> tag:

    <application
        tools:replace="android:allowBackup,icon,theme,label">
    
  6. 下载并解压缩百度推送 Android SDKDownload and unzip the Baidu Push Android SDK. 复制 libs 文件夹中的 pushservice-x.y.z jar 文件。Copy the pushservice-x.y.z jar file in the libs folder. 然后复制 Android 应用程序的 src/main/jniLibs(创建新文件夹)文件夹中的 .so 文件。Then copy the .so files in the src/main/jniLibs (create a new folder) folders of your Android application.

    Azure 通知中心 - 百度 SDK Libs

  7. 在项目的 libs 文件夹中,右键单击 pushervice-x.y.z.jar 文件,选择“作为库添加”,以便将此库包括在项目中。 In the project's libs folder, right click on the pushervice-x.y.z.jar file; select Add as Library to including this library in the project.

    Azure 通知中心 - 百度“添加为库”

  8. 打开 Android 项目的 AndroidManifest.xml 文件,添加百度 SDK 所需的权限。Open the Android project's AndroidManifest.xml file and add the permissions required by the Baidu SDK. YOURPACKAGENAME 替换为包名Replace YOURPACKAGENAME with your package name.

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.WRITE_SETTINGS" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_DOWNLOAD_MANAGER" />
    <uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
    <uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />
    !! <uses-permission android:name="baidu.push.permission.WRITE_PUSHINFOPROVIDER.YOURPACKAGENAME" />
    !!<permission android:name="baidu.push.permission.WRITE_PUSHINFOPROVIDER.YOURPACKAGENAME"android:protectionLevel="normal" />
    
    
  9. .MainActivity 活动元素后的 application 元素内添加以下配置,并替换 yourprojectname(例如 com.example.BaiduTest):Add the following configuration within the application element after the .MainActivity activity element, replacing yourprojectname (for example, com.example.BaiduTest):

    <activity
        android:name="com.baidu.android.pushservice.richmedia.MediaViewActivity"
        android:configChanges="orientation|keyboardHidden"
        android:label="MediaViewActivity" />
    <activity
        android:name="com.baidu.android.pushservice.richmedia.MediaListActivity"
        android:configChanges="orientation|keyboardHidden"
        android:label="MediaListActivity"
        android:launchMode="singleTask" />
    
    <!-- Push application definition message -->
    <receiver android:name=".MyPushMessageReceiver">
        <intent-filter>
    
            <!-- receive push message-->
            <action android:name="com.baidu.android.pushservice.action.MESSAGE" />
            <!-- receive bind,unbind,fetch,delete.. message-->
            <action android:name="com.baidu.android.pushservice.action.RECEIVE" />
            <action android:name="com.baidu.android.pushservice.action.notification.CLICK" />
        </intent-filter>
    </receiver>
    
    <receiver
        android:name="com.baidu.android.pushservice.PushServiceReceiver"
        android:process=":bdservice_v1">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
            <action android:name="com.baidu.android.pushservice.action.notification.SHOW" />
            <action android:name="com.baidu.android.pushservice.action.media.CLICK" />
            <action android:name="android.intent.action.MEDIA_MOUNTED" />
            <action android:name="android.intent.action.USER_PRESENT" />
            <action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
            <action android:name="android.intent.action.ACTION_POWER_DISCONNECTED" />
        </intent-filter>
    </receiver>
    
    <receiver
        android:name="com.baidu.android.pushservice.RegistrationReceiver"
        android:process=":bdservice_v1">
        <intent-filter>
            <action android:name="com.baidu.android.pushservice.action.METHOD" />
            <action android:name="com.baidu.android.pushservice.action.BIND_SYNC" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.PACKAGE_REMOVED" />
    
            <data android:scheme="package" />
        </intent-filter>
    </receiver>
    
    <service
        android:name="com.baidu.android.pushservice.PushService"
        android:exported="true"
        android:process=":bdservice_v1">
        <intent-filter>
            <action android:name="com.baidu.android.pushservice.action.PUSH_SERVICE" />
        </intent-filter>
    </service>
    
    <service
        android:name="com.baidu.android.pushservice.CommandService"
        android:exported="true" />
    
    <!-- Adapt the ContentProvider declaration required for the Android N system, and the write permissions include the application package name-->
    <provider
        android:name="com.baidu.android.pushservice.PushInfoProvider"
        android:authorities="com.baidu.push.example.bdpush"
        android:exported="true"
        android:protectionLevel="signature"
        android:writePermission="baidu.push.permission.WRITE_PUSHINFOPROVIDER. yourprojectname  " />
    
    <!-- API Key of the Baidu application -->
    <meta-data
        android:name="api_key"
        !!   android:value="api_key" />
    </application>
    
  10. 将名为 ConfigurationSettings.java 的新类添加到项目。Add a new class called ConfigurationSettings.java to the project.

    public class ConfigurationSettings {
        public static String API_KEY = "...";
        public static String NotificationHubName = "...";
        public static String NotificationHubConnectionString = "...";
    }
    

    使用百度云项目中的 API_KEY 设置 API_KEY 字符串的值。Set the value of the API_KEY string with the API_KEY from the Baidu Cloud Project.

    使用 Azure 门户中的通知中心名称设置 NotificationHubName 字符串的值,然后使用 Azure 门户中的 DefaultListenSharedAccessSignature 设置 NotificationHubConnectionString 的值。Set the value of the NotificationHubName string with your notification hub name from the Azure portal; and then NotificationHubConnectionString with DefaultListenSharedAccessSignature from the Azure portal.

  11. 打开 MainActivity.java,并将以下内容添加到 onCreate 方法中:Open MainActivity.java, and add the following to the onCreate method:

    PushManager.startWork(this, PushConstants.LOGIN_TYPE_API_KEY,  API_KEY );
    
  12. 添加一个名为 MyPushMessageReceiver.java 的新类,并向此类中添加以下代码:Add a new class called MyPushMessageReceiver.java, and add the following code to it. 此类用于处理从百度推送服务器收到的推送通知。It is the class that handles the push notifications that are received from the Baidu push server.

    package your.package.name;
    
    import android.content.Context;
    import android.content.Intent;
    import android.os.AsyncTask;
    import android.text.TextUtils;
    import android.util.Log;
    
    import com.baidu.android.pushservice.PushMessageReceiver;
    import com.microsoft.windowsazure.messaging.NotificationHub;
    import org.json.JSONException;
    import org.json.JSONObject;
    
    import java.util.List;
    
    public class MyPushMessageReceiver extends PushMessageReceiver {
    
        public static final String TAG = MyPushMessageReceiver.class
                .getSimpleName();
        public static NotificationHub hub = null;
        public static String mChannelId, mUserId;
    
        @Override
        public void onBind(Context context, int errorCode, String appid,
                        String userId, String channelId, String requestId) {
            String responseString = "onBind errorCode=" + errorCode + " appid="
                    + appid + " userId=" + userId + " channelId=" + channelId
                    + " requestId=" + requestId;
            Log.d(TAG, responseString);
    
            if (errorCode == 0) {
                // Binding successful
                Log.d(TAG, " Binding successful");
            }
            try {
                if (hub == null) {
                    hub = new NotificationHub(
                            ConfigurationSettings.NotificationHubName,
                            ConfigurationSettings.NotificationHubConnectionString,
                            context);
                    Log.i(TAG, "Notification hub initialized");
                }
            } catch (Exception e) {
                Log.e(TAG, e.getMessage());
            }
            mChannelId = channelId;
            mUserId = userId;
    
            registerWithNotificationHubs();
        }
        private void registerWithNotificationHubs() {
    
            new AsyncTask<Void, Void, Void>() {
                @Override
                protected Void doInBackground(Void... params) {
                    try {
                        hub.registerBaidu(mUserId, mChannelId);
                        Log.i(TAG, "Registered with Notification Hub - '"
                                + ConfigurationSettings.NotificationHubName + "'"
                                + " with UserId - '"
                                + mUserId + "' and Channel Id - '"
                                + mChannelId + "'");
                    } catch (Exception e) {
                        Log.e(TAG, e.getMessage());
                    }
                    return null;
                }
            }.execute(null, null, null);
        }
    
        @Override
        public void onMessage(Context context, String message,
                            String customContentString) {
            String messageString = " onMessage=\"" + message
                    + "\" customContentString=" + customContentString;
            Log.d(TAG, messageString);
            if (!TextUtils.isEmpty(customContentString)) {
                JSONObject customJson = null;
                try {
                    customJson = new JSONObject(customContentString);
                    String myvalue = null;
                    if (!customJson.isNull("mykey")) {
                        myvalue = customJson.getString("mykey");
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
    
        }
    
        @Override
        public void onNotificationArrived(Context context, String title, String description, String customContentString) {
            String notifyString = " Notice Arrives onNotificationArrived  title=\"" + title
                    + "\" description=\"" + description + "\" customContent="
                    + customContentString;
            Log.d(TAG, notifyString);
            if (!TextUtils.isEmpty(customContentString)) {
                JSONObject customJson = null;
                try {
                    customJson = new JSONObject(customContentString);
                    String myvalue = null;
                    if (!customJson.isNull("mykey")) {
                        myvalue = customJson.getString("mykey");
                    }
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    
        @Override
        public void onNotificationClicked(Context context, String title, String description, String customContentString) {
            String notifyString = " onNotificationClicked title=\"" + title + "\" description=\""
                    + description + "\" customContent=" + customContentString;
            Log.d(TAG, notifyString);
            Intent intent = new Intent(context.getApplicationContext(),MainActivity.class);
            intent.putExtra("title",title);
            intent.putExtra("description",description);
            intent.putExtra("isFromNotify",true);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.getApplicationContext().startActivity(intent);
    
        }
    
        @Override
        public void onSetTags(Context context, int errorCode,
                            List<String> successTags, List<String> failTags, String requestId) {
            String responseString = "onSetTags errorCode=" + errorCode
                    + " successTags=" + successTags + " failTags=" + failTags
                    + " requestId=" + requestId;
            Log.d(TAG, responseString);
    
        }
    
        @Override
        public void onDelTags(Context context, int errorCode,
                            List<String> successTags, List<String> failTags, String requestId) {
            String responseString = "onDelTags errorCode=" + errorCode
                    + " successTags=" + successTags + " failTags=" + failTags
                    + " requestId=" + requestId;
            Log.d(TAG, responseString);
    
        }
    
        @Override
        public void onListTags(Context context, int errorCode, List<String> tags,
                            String requestId) {
            String responseString = "onListTags errorCode=" + errorCode + " tags="
                    + tags;
            Log.d(TAG, responseString);
    
        }
    
        @Override
        public void onUnbind(Context context, int errorCode, String requestId) {
            String responseString = "onUnbind errorCode=" + errorCode
                    + " requestId = " + requestId;
            Log.d(TAG, responseString);
    
            if (errorCode == 0) {
                // Unbinding is successful
                Log.d(TAG, " Unbinding is successful ");
            }
        }
    }
    

向应用程序发送通知Send notifications to your app

可以在 Azure 门户中快速测试通知接收情况:使用通知中心配置屏幕中的“发送” 按钮,如以下屏幕所示:You can quickly test receiving notifications from the Azure portal: use the Send button in the notification hub configuration screen, as shown in the following screens:

通常,推送通知是在后端服务(例如,移动服务,或者使用兼容库的 ASP.NET)中发送的。Push notifications are normally sent in a back-end service like Mobile Services or ASP.NET using a compatible library. 如果后端没有可用的库,则可直接使用 REST API 发送通知消息。If a library is not available for your back-end, you can use the REST API directly to send notification messages.

为简单起见,本教程使用一个控制台应用演示如何通过 .NET SDK 来发送通知。For simplicity, this tutorial uses a console app as a demonstration on how to send a notification with the .NET SDK. 但是,建议你接下来学习使用通知中心向用户推送通知教程,了解如何从 ASP.NET 后端发送通知。However, we recommend the Use Notification Hubs to push notifications to users tutorial as the next step for sending notifications from an ASP.NET backend.

下面是用于发送通知的不同方法:Here are different approaches for sending notifications:

(可选)通过 .NET 控制台应用发送通知。(Optional) Send notifications from a .NET console app.

在本部分,我们将演示如何使用 .NET 控制台应用发送通知。In this section, we show sending a notification using a .NET console app.

  1. 创建新的 Visual C# 控制台应用程序:Create a new Visual C# console application:

  2. 在“包管理器控制台”窗口中,将“默认项目”设置为新的控制台应用程序项目,然后在控制台窗口中执行以下命令: In the Package Manager Console window, set the Default project to your new console application project, and then in the console window, execute the following command:

    Install-Package Microsoft.Azure.NotificationHubs
    

    此指令会使用 Microsoft.Azure.Notification Hubs NuGet 包添加对 Azure 通知中心 SDK 的引用。This instruction adds a reference to the Azure Notification Hubs SDK using the Microsoft.Azure.Notification Hubs NuGet package.

  3. 打开 Program.cs 文件并添加以下 using 语句:Open the file Program.cs and add the following using statement:

    using Microsoft.Azure.NotificationHubs;
    
  4. Program 类中添加以下方法,并使用自己的值替换 DefaultFullSharedAccessSignatureSASConnectionStringNotificationHubNameIn your Program class, add the following method and replace DefaultFullSharedAccessSignatureSASConnectionString and NotificationHubName with the values that you have.

    private static async void SendNotificationAsync()
    {
        NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString("DefaultFullSharedAccessSignatureSASConnectionString", "NotificationHubName");
        string message = "{\"title\":\"((Notification title))\",\"description\":\"Hello from Azure\"}";
        var result = await hub.SendBaiduNativeNotificationAsync(message);
    }
    
  5. Main 方法中添加以下行:Add the following lines in your Main method:

    SendNotificationAsync();
    Console.ReadLine();
    

测试应用程序Test your app

要使用实际的手机测试此应用,只需使用 USB 电缆将该手机连接到你的计算机。To test this app with an actual phone, just connect the phone to your computer by using a USB cable. 此操作会将应用加载到连接的手机中。This action loads your app onto the attached phone.

若要使用模拟器测试此应用,请在 Android Studio 顶部工具栏中单击“运行”,然后选择用于启动模拟器、加载和运行应用的应用。 To test this app with the emulator, on the Android Studio top toolbar, click Run, and then select your app: it starts the emulator, loads, and runs the app.

该应用将从百度推送通知服务检索 userIdchannelId,并注册到通知中心。The app retrieves the userId and channelId from the Baidu Push notification service and registers with the notification hub.

若要发送测试通知,可以使用 Azure 门户的调试选项卡。To send a test notification, you can use the debug tab of the Azure portal. 如果为 Visual Studio 生成了 .NET 控制台应用程序,只需在 Visual Studio 中按 F5 键以运行该应用程序。If you built the .NET console application for Visual Studio, just press the F5 key in Visual Studio to run the application. 该应用程序会发送一条通知,该通知显示在设备或模拟器的顶部通知区域。The application sends a notification that appears in the top notification area of your device or emulator.