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


Java GcmPubSub类代码示例

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


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

示例1: doInBackground

import com.google.android.gms.gcm.GcmPubSub; //导入依赖的package包/类
@Override
protected String[] doInBackground(String... topics) {
    final GcmPubSub pubSub = GcmPubSub.getInstance(getContext());
    try {
        SharedPreferences sharedPreferences =
                PreferenceManager.getDefaultSharedPreferences(getContext());
        final String token = sharedPreferences.getString(AufzugswaechterPreferences.TOKEN, null);
        if (token != null) {
            for (String topic : topics) {
                toggleSubscription(pubSub, topic, token);
            }
            return topics;
        } else {
            return null;
        }
    } catch (IOException ioex) {
        // TODO error reporting
        ioex.printStackTrace();
        return null;
    } catch (Exception ex) {
        ex.printStackTrace();
        return null;
    }
}
 
开发者ID:highsource,项目名称:aufzugswaechter-android-app,代码行数:25,代码来源:AbstractToggleTopicSubscribtionTask.java

示例2: 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

示例3: onHandleIntent

import com.google.android.gms.gcm.GcmPubSub; //导入依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
	String token = intent.getStringExtra(TOKEN);
	if (TextUtils.isEmpty(token)) {
		Logs.gcm("Empty token.");
		return;
	}
	if (!TextUtils.isEmpty(DEFAULT_TOPIC)) {

		Logs.gcm("subscribing to topic: " + DEFAULT_TOPIC + " with token " + token);
		try {
			GcmPubSub.getInstance(this).subscribe(token, "/topics/" + DEFAULT_TOPIC, null);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
 
开发者ID:iit-rende,项目名称:thesapp-android,代码行数:18,代码来源:GcmTopicRegisterService.java

示例4: 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

示例5: registerToStoryTopic

import com.google.android.gms.gcm.GcmPubSub; //导入依赖的package包/类
public void registerToStoryTopic(final User user, final Story story) {
    new AsyncTask<Void,Void,Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            try {
                if(user.getPushIdentity() != null) {
                    GcmPubSub gcmPubStub = GcmPubSub.getInstance(context);
                    gcmPubStub.subscribe(user.getPushIdentity(), getTopicName(STORY_TOPICS_PATH, story.getKey()), null);
                }
            } catch(Exception exception) {
                Log.e(TAG, "registerToChatRoomTopic ", exception);
            }
            return null;
        }
    }.execute();
}
 
开发者ID:rapidpro,项目名称:ureport-android,代码行数:17,代码来源:GcmTopicManager.java

示例6: registerToChatRoomTopic

import com.google.android.gms.gcm.GcmPubSub; //导入依赖的package包/类
public void registerToChatRoomTopic(final User user, final String chatRoomKey) {
    new AsyncTask<Void,Void,Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            try {
                if(user.getPushIdentity() != null) {
                    GcmPubSub gcmPubStub = GcmPubSub.getInstance(context);
                    gcmPubStub.subscribe(user.getPushIdentity(), getTopicName(CHAT_TOPICS_PATH, chatRoomKey), null);
                }
            } catch(Exception exception) {
                Log.e(TAG, "registerToChatRoomTopic ", exception);
            }
            return null;
        }
    }.execute();
}
 
开发者ID:rapidpro,项目名称:ureport-android,代码行数:17,代码来源:GcmTopicManager.java

示例7: unregisterToChatRoomTopic

import com.google.android.gms.gcm.GcmPubSub; //导入依赖的package包/类
public void unregisterToChatRoomTopic(final User user, final String chatRoomKey) {
    new AsyncTask<Void,Void,Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            try {
                if (user.getPushIdentity() != null) {
                    GcmPubSub gcmPubStub = GcmPubSub.getInstance(context);
                    gcmPubStub.unsubscribe(user.getPushIdentity(), getTopicName(CHAT_TOPICS_PATH, chatRoomKey));
                }
            } catch (Exception exception) {
                Log.e(TAG, "unregisterToChatRoomTopic ", exception);
            }
            return null;
        }
    }.execute();
}
 
开发者ID:rapidpro,项目名称:ureport-android,代码行数:17,代码来源:GcmTopicManager.java

示例8: subscribeToTopics

import com.google.android.gms.gcm.GcmPubSub; //导入依赖的package包/类
private void subscribeToTopics(JSONArray topics, String registrationToken) {
    if (topics != null) {
        String topic = null;
        for (int i=0; i<topics.length(); i++) {
            try {
                topic = topics.optString(i, null);
                if (topic != null) {
                    Log.d(LOG_TAG, "Subscribing to topic: " + topic);
                    GcmPubSub.getInstance(getApplicationContext()).subscribe(registrationToken, "/topics/" + topic, null);
                }
            } catch (IOException e) {
                Log.e(LOG_TAG, "Failed to subscribe to topic: " + topic, e);
            }
        }
    }
}
 
开发者ID:trecrts,项目名称:trecrts-eval,代码行数:17,代码来源:PushPlugin.java

示例9: unsubscribeFromTopics

import com.google.android.gms.gcm.GcmPubSub; //导入依赖的package包/类
private void unsubscribeFromTopics(JSONArray topics, String registrationToken) {
    if (topics != null) {
        String topic = null;
        for (int i=0; i<topics.length(); i++) {
            try {
                topic = topics.optString(i, null);
                if (topic != null) {
                    Log.d(LOG_TAG, "Unsubscribing to topic: " + topic);
                    GcmPubSub.getInstance(getApplicationContext()).unsubscribe(registrationToken, "/topics/" + topic);
                }
            } catch (IOException e) {
                Log.e(LOG_TAG, "Failed to unsubscribe to topic: " + topic, e);
            }
        }
    }
}
 
开发者ID:trecrts,项目名称:trecrts-eval,代码行数:17,代码来源:PushPlugin.java

示例10: subscribeToTopic

import com.google.android.gms.gcm.GcmPubSub; //导入依赖的package包/类
/**
 * Subscribes the client to a specific topic.
 * /topics/ prefix is not necessary.
 *
 * @param topic The topic to subscribe to
 *
 * @return A task that can resolved upon subscribing.
 */
public Task<Void> subscribeToTopic(final String topic) {
    final GcmPubSub pubSub = GcmPubSub.getInstance(getContext());
    final String topicKey = String.format("/topics/%s", topic);
    final InstanceID instanceId = InstanceID.getInstance(getContext());

    final TaskCompletionSource<Void> future = new TaskCompletionSource<>();

    getRegistrationToken(instanceId, _info.getSenderId()).addOnCompleteListener(new OnCompleteListener<String>() {
        @Override
        public void onComplete(@NonNull final Task<String> task) {
            if (!task.isSuccessful()) {
                future.setException(task.getException());
            }

            new AsyncTask<Object, Integer, String>() {
                @Override
                protected String doInBackground(final Object[] ignored) {

                    try {
                        pubSub.subscribe(task.getResult(), topicKey, null);
                    } catch (final IOException e) {
                        Log.e(TAG, "Error subscribing to " + topicKey, e);
                        future.setException(e);
                        return null;
                    }

                    future.setResult(null);
                    return null;
                }
            }.execute();
        }
    });

    return future.getTask();
}
 
开发者ID:mongodb,项目名称:stitch-android-sdk,代码行数:44,代码来源:GCMPushClient.java

示例11: unsubscribeFromTopic

import com.google.android.gms.gcm.GcmPubSub; //导入依赖的package包/类
/**
 * Subscribes the client to a specific topic.
 * /topics/ prefix is not necessary.
 *
 * @param topic The topic to unsubscribe from
 *
 * @return A task that can resolved upon subscribing.
 */
public Task<Void> unsubscribeFromTopic(final String topic) {
    final GcmPubSub pubSub = GcmPubSub.getInstance(getContext());
    final String topicKey = String.format("/topics/%s", topic);
    final InstanceID instanceId = InstanceID.getInstance(getContext());

    final TaskCompletionSource<Void> future = new TaskCompletionSource<>();

    getRegistrationToken(instanceId, _info.getSenderId()).addOnCompleteListener(new OnCompleteListener<String>() {
        @Override
        public void onComplete(@NonNull final Task<String> task) {
            if (!task.isSuccessful()) {
                future.setException(task.getException());
            }

            new AsyncTask<Object, Integer, String>() {
                @Override
                protected String doInBackground(final Object[] ignored) {

                    try {
                        pubSub.unsubscribe(task.getResult(), topicKey);
                    } catch (final IOException e) {
                        Log.e(TAG, "Error unsubscribing from " + topicKey, e);
                        future.setException(e);
                        return null;
                    }

                    future.setResult(null);
                    return null;
                }
            }.execute();
        }
    });

    return future.getTask();
}
 
开发者ID:mongodb,项目名称:stitch-android-sdk,代码行数:44,代码来源:GCMPushClient.java

示例12: 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

示例13: 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

示例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
 */
// [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

示例15: 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


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