当前位置: 首页>>代码示例>>Java>>正文


Java GcmPubSub.subscribe方法代码示例

本文整理汇总了Java中com.google.android.gms.gcm.GcmPubSub.subscribe方法的典型用法代码示例。如果您正苦于以下问题:Java GcmPubSub.subscribe方法的具体用法?Java GcmPubSub.subscribe怎么用?Java GcmPubSub.subscribe使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.android.gms.gcm.GcmPubSub的用法示例。


在下文中一共展示了GcmPubSub.subscribe方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: subscribeToTopic

import com.google.android.gms.gcm.GcmPubSub; //导入方法依赖的package包/类
/**
 * Subscribe to a topic
 */
public void subscribeToTopic(String topic) {
    GcmPubSub pubSub = GcmPubSub.getInstance(getApplicationContext());
    InstanceID instanceID = InstanceID.getInstance(getApplicationContext());
    String token = null;
    String gcm_server_sender_id = SharedPref.getSenderId(GcmIntentService.this);
    try {
        token = instanceID.getToken(gcm_server_sender_id,
                GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
        if (token != null) {
            pubSub.subscribe(token, "/topics/" + topic, null);
            Log.d(TAG, "Subscribed to topic: " + topic);
        } else {
            Log.d(TAG, "error: gcm registration id is null");
        }
    } catch (IOException e) {
        Log.e(TAG, "Topic subscribe error. Topic: " + topic + ", error: " + e.getMessage());
        Toast.makeText(getApplicationContext(), "Topic subscribe error. Topic: " + topic + ", error: " + e.getMessage(), Toast.LENGTH_SHORT).show();
    }
}
 
开发者ID:saikiapriyam,项目名称:PushEZ,代码行数:23,代码来源:GcmIntentService.java

示例2: subscribeWeatherUpdates

import com.google.android.gms.gcm.GcmPubSub; //导入方法依赖的package包/类
public static void subscribeWeatherUpdates(Context context) throws IOException {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    String token = prefs.getString(SettingsFragment.PREF_GCM_TOKEN, null);
    boolean subscribe = prefs.getBoolean(SettingsFragment.PREF_WEATHER_GCM, false);

    if (token == null) {
        Log.i(TAG, "Subscribe weather updates: no token");
        return;
    }

    String topic = "/topics/weather";
    GcmPubSub pubSub = GcmPubSub.getInstance(context);
    if (subscribe)
        pubSub.subscribe(token, topic, null);
    else
        pubSub.unsubscribe(token, topic);
    Log.i(TAG, "Subcribe " + topic + "=" + subscribe);
}
 
开发者ID:M66B,项目名称:BackPackTrackII,代码行数:19,代码来源:GcmService.java

示例3: subscribeTopics

import com.google.android.gms.gcm.GcmPubSub; //导入方法依赖的package包/类
private void subscribeTopics(String token){

        GcmPubSub pubSub = GcmPubSub.getInstance(this);
        try{
            Log.i(TAG, "Subscribing to " + TOPIC_NAME);
            pubSub.subscribe(token, "/topics/" + TOPIC_NAME, null);
            Log.i(TAG, "Subscribed to " + TOPIC_NAME + " with success");
        } catch (Exception e){
            Log.e(TAG,"Failed to subscribe to " + TOPIC_NAME,e);
        }

    }
 
开发者ID:PacktPublishing,项目名称:Asynchronous-Android-Programming,代码行数:13,代码来源:RegistrationIntentService.java

示例4: subscribeTopics

import com.google.android.gms.gcm.GcmPubSub; //导入方法依赖的package包/类
/**
 * Subscribe to any GCM topics of interest, as defined by the TOPICS constant.
 *
 * @param token GCM token
 * @throws IOException if unable to reach the GCM PubSub service
 */
// [START subscribe_topics]
private void subscribeTopics(String token) throws IOException {
    GcmPubSub pubSub = GcmPubSub.getInstance(this);
    for (String topic : TOPICS) {
        pubSub.subscribe(token, "/topics/" + topic, null);
    }
}
 
开发者ID:mstfnacar,项目名称:foodfeed,代码行数:14,代码来源:RegistrationIntentService.java

示例5: subscribeTopics

import com.google.android.gms.gcm.GcmPubSub; //导入方法依赖的package包/类
/**
 * Subscribe to any GCM topics of interest, as defined by the TOPICS constant.
 *
 * @param token GCM token
 * @throws IOException if unable to reach the GCM PubSub service
 */
// [START subscribe_topics]
private void subscribeTopics(String token) throws IOException {
  GcmPubSub pubSub = GcmPubSub.getInstance(this);
  for (String topic : TOPICS) {
    pubSub.subscribe(token, "/topics/" + topic, null);
  }
}
 
开发者ID:rakshitsoni02,项目名称:newsApp,代码行数:14,代码来源:RegistrationIntentService.java

示例6: subscribeTopics

import com.google.android.gms.gcm.GcmPubSub; //导入方法依赖的package包/类
/**
 * Subscribe to any GCM topics of interest, as defined by the TOPICS constant.
 *
 * @param token GCM token
 * @throws IOException if unable to reach the GCM PubSub service
 */
// [START subscribe_topics]
private void subscribeTopics(String token) throws IOException {

    GcmPubSub pubSub = GcmPubSub.getInstance(this);

    for (String topic : TOPICS) {
        pubSub.subscribe(token, TOPICS_SERVICE + topic, null);
    }
}
 
开发者ID:Telecooperation,项目名称:assistance-platform-client-sdk-android,代码行数:16,代码来源:GcmRegistrationIntentService.java

示例7: subscribeTopics

import com.google.android.gms.gcm.GcmPubSub; //导入方法依赖的package包/类
/**
 * Subscribe to any GCM topics of interest, as defined by the TOPICS constant.
 *
 * @param token GCM token
 * @throws IOException if unable to reach the GCM PubSub service
 */
// [START subscribe_topics]
private void subscribeTopics(String token) throws IOException {
    GcmPubSub pubSub = GcmPubSub.getInstance(this);
    for (String topic : TOPICS) {
        pubSub.subscribe(token, "/topics/" + topic, null);
    }
    }
 
开发者ID:JohnnyJiang,项目名称:Our_days,代码行数:14,代码来源:RegistrationIntentService.java

示例8: subscribeTopics

import com.google.android.gms.gcm.GcmPubSub; //导入方法依赖的package包/类
/**
 * Subscribe to any GCM topics of interest, as defined by the TOPICS constant.
 *
 * @param token GCM token
 * @throws IOException if unable to reach the GCM PubSub service
 */
private void subscribeTopics(Context context, String token) throws IOException {
    GcmPubSub pubSub = GcmPubSub.getInstance(context);
    for (String topic : TOPICS) {
        pubSub.subscribe(token, "/topics/" + topic, null);
    }
}
 
开发者ID:infobip,项目名称:mobile-messaging-sdk-android,代码行数:13,代码来源:RegistrationTokenHandler.java

示例9: subscribeTopics

import com.google.android.gms.gcm.GcmPubSub; //导入方法依赖的package包/类
/**
 * subscribe user to topics in gcm
 *
 * @param token
 */
private void subscribeTopics(String token){
    GcmPubSub pubSub = GcmPubSub.getInstance(this);
    for(String topic : TOPICS){
        try {
            pubSub.subscribe(token, "/topics/" + topic, null);
        } catch (IOException e) {
            FirebaseCrash.report(e);
        }
    }
}
 
开发者ID:BandUp,项目名称:band-up-android,代码行数:16,代码来源:RegistrationIntentService.java

示例10: subscribeTopics

import com.google.android.gms.gcm.GcmPubSub; //导入方法依赖的package包/类
/**
 * Subscribe to any GCM topics of interest, as defined by the TOPICS constant.
 *
 * @param token GCM token
 * @throws IOException if unable to reach the GCM PubSub service
 */
// [START subscribe_topics]
private void subscribeTopics(String token) throws IOException {
    for (String topic : TOPICS) {
        GcmPubSub pubSub = GcmPubSub.getInstance(this);
        pubSub.subscribe(token, "/topics/" + topic, null);
    }
}
 
开发者ID:atahani,项目名称:telepathy-android,代码行数:14,代码来源:RegistrationIntentService.java

示例11: subscribeTopics

import com.google.android.gms.gcm.GcmPubSub; //导入方法依赖的package包/类
/**
 * Subscribe to any GCM topics of interest, as defined by the TOPICS constant.
 *
 * @param token GCM token
 * @throws IOException if unable to reach the GCM PubSub service
 */

private void subscribeTopics(String token) throws IOException {
    GcmPubSub pubSub = GcmPubSub.getInstance(this);
    for (String topic : TOPICS) {
        pubSub.subscribe(token, "/topics/" + topic, null);
    }
}
 
开发者ID:lukamarin,项目名称:Rocket.Chat-android,代码行数:14,代码来源:RocketRegistrationIntentService.java

示例12: subscribeBroadcasts

import com.google.android.gms.gcm.GcmPubSub; //导入方法依赖的package包/类
public static void subscribeBroadcasts(Context context) throws IOException {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    String token = prefs.getString(SettingsFragment.PREF_GCM_TOKEN, null);

    if (token == null) {
        Log.i(TAG, "Subscribe broadcasts: no token");
        return;
    }

    String topic = "/topics/broadcasts";
    GcmPubSub pubSub = GcmPubSub.getInstance(context);
    pubSub.subscribe(token, topic, null);
    Log.i(TAG, "Subscribed to " + topic);
}
 
开发者ID:M66B,项目名称:BackPackTrackII,代码行数:15,代码来源:GcmService.java

示例13: registerToChatRoomTopics

import com.google.android.gms.gcm.GcmPubSub; //导入方法依赖的package包/类
public void registerToChatRoomTopics(String pushIdentity, User user) {
    try {
        Set<String> chatRooms = user.getChatRooms().keySet();

        for (String chatRoom : chatRooms) {
            GcmPubSub gcmPubSub = GcmPubSub.getInstance(context);
            gcmPubSub.subscribe(pushIdentity, getTopicName(CHAT_TOPICS_PATH, chatRoom), null);
        }
    } catch (Exception exception) {
        Log.e(TAG, "registerToChatRoomTopics ", exception);
    }
}
 
开发者ID:rapidpro,项目名称:ureport-android,代码行数:13,代码来源:GcmTopicManager.java

示例14: subscribeTopics

import com.google.android.gms.gcm.GcmPubSub; //导入方法依赖的package包/类
/**
 * Subscribe to any GCM topics of interest, as defined by the TOPICS constant.
 *
 * @param token GCM token
 * @throws IOException if unable to reach the GCM PubSub service
 */
private void subscribeTopics(String token) throws IOException {
    for (String topic : TOPICS) {
        GcmPubSub pubSub = GcmPubSub.getInstance(this);
        pubSub.subscribe(token, "/topics/" + topic, null);
    }
}
 
开发者ID:tech-team,项目名称:decider-android,代码行数:13,代码来源:GcmRegistrationIntentService.java

示例15: subscribeTopics

import com.google.android.gms.gcm.GcmPubSub; //导入方法依赖的package包/类
/**
 * Subscribe to any GCM topics of interest, as defined by the TOPICS constant.
 *
 * @param gcmId GCM gcmId
 * @throws IOException if unable to reach the GCM PubSub service
 */
// [START subscribe_topics]
private void subscribeTopics(String gcmId) throws IOException {
    for (String topic : TOPICS) {
        GcmPubSub pubSub = GcmPubSub.getInstance(this);
        pubSub.subscribe(gcmId, "/topics/" + topic, null);
    }
}
 
开发者ID:NKPmedia,项目名称:VertretungsplanApp,代码行数:14,代码来源:RegistrationIntentService.java


注:本文中的com.google.android.gms.gcm.GcmPubSub.subscribe方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。