本文整理汇总了Java中com.google.firebase.messaging.FirebaseMessaging类的典型用法代码示例。如果您正苦于以下问题:Java FirebaseMessaging类的具体用法?Java FirebaseMessaging怎么用?Java FirebaseMessaging使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FirebaseMessaging类属于com.google.firebase.messaging包,在下文中一共展示了FirebaseMessaging类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendMessage
import com.google.firebase.messaging.FirebaseMessaging; //导入依赖的package包/类
public void sendMessage (final String data) {
FirebaseMessaging fm = FirebaseMessaging.getInstance();
String token = FirebaseInstanceId.getInstance().getToken();
String msgID = DigestUtils.sha1Hex(token + System.currentTimeMillis());
String SENDER_ID = "someID";
RemoteMessage.Builder RMBuilder =
new RemoteMessage.Builder(SENDER_ID + "@gcm.googleapis.com");
RMBuilder.setMessageId(msgID);
Map<String, Object> mapData = Utils.jsonToMap(data);
for (Map.Entry<String, Object> entry : mapData.entrySet()) {
RMBuilder.addData(entry.getKey(), entry.getValue().toString());
}
fm.send(RMBuilder.build());
}
示例2: onOptionsItemSelected
import com.google.firebase.messaging.FirebaseMessaging; //导入依赖的package包/类
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.subscribe:
FirebaseMessaging.getInstance().subscribeToTopic("pushNotifications");
Toast.makeText(MainActivity.this, "Subscribed to Topic: Push Notifications", Toast.LENGTH_SHORT).show();
break;
case R.id.unsubscribe:
FirebaseMessaging.getInstance().unsubscribeFromTopic("pushNotifications");
Toast.makeText(MainActivity.this, "Unsubscribed to Topic: Push Notifications", Toast.LENGTH_SHORT).show();
break;
case R.id.sign_out_menu:
AuthUI.getInstance().signOut(this);
break;
default:
return super.onOptionsItemSelected(item);
}
return true;}
示例3: onCreate
import com.google.firebase.messaging.FirebaseMessaging; //导入依赖的package包/类
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_server_status);
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitleTextColor(ContextCompat.getColor(this, R.color.gold));
setSupportActionBar(toolbar);
findViewById(R.id.fab).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
final Intent browserIntent =
new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.BROWSER_FORUMS_URL));
startActivity(browserIntent);
}
});
content = (ViewGroup) findViewById(R.id.content);
sharedPref = getSharedPreferences(
getString(R.string.preference_file_key), Context.MODE_PRIVATE);
FirebaseMessaging.getInstance().subscribeToTopic("server-status");
}
示例4: handlings
import com.google.firebase.messaging.FirebaseMessaging; //导入依赖的package包/类
private void handlings(String type, View view) {
if (! bloodType.equals(type)) {
clearButtons();
view.setBackgroundColor(getResources().getColor(R.color.button_selected));
saveInfo(type);
getInfo();
unsubscribe();
FirebaseMessaging.getInstance().subscribeToTopic("blood-" + type);
} else if(bloodType.equals(type)) {
clearButtons();
unsubscribe();
saveInfo("");
bloodType = "";
}
}
示例5: onCreate
import com.google.firebase.messaging.FirebaseMessaging; //导入依赖的package包/类
@Override
public void onCreate() {
OneSheeldSdk.init(this);
context = getApplicationContext();
setAppPreferences(getSharedPreferences(APP_PREF_NAME, MODE_PRIVATE));
appFont = Typeface.createFromAsset(getAssets(), "Roboto-Light.ttf");
parseSocialKeys();
initTaskerPins();
isDebuggable = (0 != (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE));
if (isDebuggable() && !FirebaseApp.getApps(this).isEmpty())
FirebaseMessaging.getInstance().subscribeToTopic("dev");
OneSheeldSdk.setDebugging(isDebuggable);
connectionTime = 0;
AppShields.getInstance().init(getRememberedShields());
initCrashlyticsAndUncaughtThreadHandler();
super.onCreate();
}
示例6: onCreate
import com.google.firebase.messaging.FirebaseMessaging; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
viewPager = (ViewPager) findViewById(R.id.viewpager);
setupViewPager(viewPager);
viewPager.setOffscreenPageLimit(ITEM_COUNT);
tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(viewPager);
mRegistrationBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Config.REGISTRATION_COMPLETE)) {
FirebaseMessaging.getInstance().subscribeToTopic(Config.TOPIC_GLOBAL);
} else if (intent.getAction().equals(Config.PUSH_NOTIFICATION)) {
// new push notification is received
}
}
};
}
示例7: signOut
import com.google.firebase.messaging.FirebaseMessaging; //导入依赖的package包/类
public void signOut() {
view.showProgress(R.string.signing_out);
signOutSubscriber = new DefaultSubscriber<String>(view) {
@Override
public void onNext(String userId) {
super.onNext(userId);
view.hideProgress();
view.navigateToSplash();
FirebaseMessaging.getInstance().unsubscribeFromTopic("user_" + userId);
}
@Override
public void onError(Throwable e) {
super.onError(e);
view.showMessage(R.string.sign_out_error);
view.hideProgress();
}
};
authManager.signOut(signOutSubscriber);
}
示例8: signInWithGoogle
import com.google.firebase.messaging.FirebaseMessaging; //导入依赖的package包/类
public void signInWithGoogle(GoogleSignInAccount googleSignInAccount) {
signInSubscriber = new DefaultSubscriber<String>(view) {
@Override
public void onNext(String userId) {
super.onNext(userId);
view.navigateToUsers();
view.hideProgress();
FirebaseMessaging.getInstance().subscribeToTopic("user_" + userId);
}
@Override
public void onError(Throwable e) {
super.onError(e);
view.showMessage(R.string.authentication_failed);
view.hideProgress();
}
};
authManager.signInGoogle(googleSignInAccount, signInSubscriber, createUser);
}
示例9: signOut
import com.google.firebase.messaging.FirebaseMessaging; //导入依赖的package包/类
private void signOut() {
mAuth.signOut();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
SharedPreferences.Editor editor = prefs.edit();
editor.putString("ustype", "0").apply();
editor.putString("usadmin", "0").apply();
editor.putString("usico", "0").apply();
editor.putString("usosc", "0").apply();
editor.putString("usatw", "0").apply();
editor.putString("usuid", "0").apply();
editor.commit();
String approvetopic = "approve" + userico;
String mytopic = "mytopic" + myuserid;
FirebaseMessaging.getInstance().unsubscribeFromTopic(mytopic);
FirebaseMessaging.getInstance().unsubscribeFromTopic(approvetopic);
updateUI(null);
}
示例10: onCreate
import com.google.firebase.messaging.FirebaseMessaging; //导入依赖的package包/类
@Override public void onCreate() {
super.onCreate();
MultiDex.install(this);
// Logging
if (BuildConfig.DEBUG) {
Jot.add(new Jot.DebugLogger());
} else {
Jot.add(new CrashlyticsLogger());
}
// Fabric
Fabric.with(this, new Crashlytics(), new Answers());
Analytics.add(AnswersLogger.getInstance());
// Crashlytics
Crashlytics.setString("GIT_SHA", BuildConfig.GIT_SHA);
Crashlytics.setString("BUILD_TIME", BuildConfig.BUILD_TIME);
FirebaseMessaging.getInstance().subscribeToTopic("main-" + BuildConfig.FLAVOR);
}
示例11: onSharedPreferenceChanged
import com.google.firebase.messaging.FirebaseMessaging; //导入依赖的package包/类
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
String keyReceiveNotification = StripSharedPreferencesDataSource.KEY_RECEIVE_NOTIFICATION;
if (key.compareTo(keyReceiveNotification) == 0) {
boolean receiveNotification = sharedPreferences.getBoolean(keyReceiveNotification, true);
FirebaseApp.initializeApp(getActivity().getApplicationContext());
if (receiveNotification) {
FirebaseMessaging.getInstance().subscribeToTopic(Configuration.TOPIC_NAME);
} else {
FirebaseMessaging.getInstance().unsubscribeFromTopic(Configuration.TOPIC_NAME);
}
}
}
示例12: onSlideChanged
import com.google.firebase.messaging.FirebaseMessaging; //导入依赖的package包/类
@Override
public void onSlideChanged(@Nullable Fragment oldFragment, @Nullable Fragment newFragment) {
super.onSlideChanged(oldFragment, newFragment);
currentSlide++;
if (currentSlide.equals(totalSlides)) {
if (!getTaskFragment().isJobFinished()) {
setSwipeLock(true);
setNextPageSwipeLock(false);
}
// Ask Firebase to register the device in the topic. Used for receiving notification.
FirebaseApp.initializeApp(getApplicationContext());
FirebaseMessaging.getInstance().subscribeToTopic(Configuration.TOPIC_NAME);
}
}
示例13: onCreate
import com.google.firebase.messaging.FirebaseMessaging; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity_main);
FirebaseMessaging.getInstance().subscribeToTopic("test");
FirebaseInstanceId.getInstance().getToken();
AM = this;
loadFirebase();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getSupportActionBar().setElevation(0);
}
setTitle("All Events");
viewPager = (ViewPager) findViewById(R.id.viewPager);
//setRetainInstance(true);
viewPager.setOffscreenPageLimit(4);
setAdapterfn();
}
示例14: onSettingsChange
import com.google.firebase.messaging.FirebaseMessaging; //导入依赖的package包/类
public static void onSettingsChange(SharedPreferences sharedPreferences, Resources resources, String key) {
switch (key) {
case NOTIFICATIONS_NEWS:
unsubscribeFromAllNews(resources);
String news = sharedPreferences.getString(NOTIFICATIONS_NEWS, "none");
if (news.equals("none")) {
break;
}
String topic = "news-" + news;
FirebaseMessaging.getInstance().subscribeToTopic(topic);
if (BuildConfig.DEBUG) {
FirebaseMessaging.getInstance().subscribeToTopic(topic + "-debug");
}
break;
case NOTIFICATIONS_PATCH:
checkAndUpdatePatchTopic(sharedPreferences, resources);
break;
}
}
示例15: checkAndUpdatePatchTopic
import com.google.firebase.messaging.FirebaseMessaging; //导入依赖的package包/类
public static void checkAndUpdatePatchTopic(SharedPreferences sharedPreferences, Resources resources) {
boolean subscribed = sharedPreferences.getBoolean(NOTIFICATIONS_PATCH, true);
String intendedTopic = "patch-" + BuildConfig.CARD_DATA_VERSION;
String key = resources.getString(R.string.pref_patch_notifications_topic_key);
String topic = sharedPreferences.getString(key, null);
if (subscribed) {
if (!intendedTopic.equals(topic)) {
if (topic != null) {
FirebaseMessaging.getInstance().unsubscribeFromTopic(topic);
}
FirebaseMessaging.getInstance().subscribeToTopic(intendedTopic);
sharedPreferences.edit().putString(key, intendedTopic).apply();
}
} else {
if (topic != null) {
FirebaseMessaging.getInstance().unsubscribeFromTopic(topic);
sharedPreferences.edit().remove(key).apply();
}
}
}