當前位置: 首頁>>代碼示例>>Java>>正文


Java FirebaseMessaging類代碼示例

本文整理匯總了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());
}
 
開發者ID:FrogSquare,項目名稱:GodotFireBase,代碼行數:20,代碼來源:Notification.java

示例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;}
 
開發者ID:SinanYilmaz9,項目名稱:CloudFunctionsExample,代碼行數:22,代碼來源:MainActivity.java

示例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");
}
 
開發者ID:dkarivalis,項目名稱:SWGEmuServerStatus,代碼行數:23,代碼來源:ServerStatusActivity.java

示例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 = "";
	}
}
 
開發者ID:team-htbr,項目名稱:1617PROJ1Bloeddonatie-app,代碼行數:18,代碼來源:SubscribeBloodtypeActivity.java

示例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();
}
 
開發者ID:Dnet3,項目名稱:CustomAndroidOneSheeld,代碼行數:18,代碼來源:OneSheeldApplication.java

示例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
            }
        }
    };
}
 
開發者ID:anandwana001,項目名稱:Tech-Jalsa,代碼行數:27,代碼來源:MainActivity.java

示例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);
}
 
開發者ID:ihorvitruk,項目名稱:buddysearch,代碼行數:22,代碼來源:UsersPresenter.java

示例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);
}
 
開發者ID:ihorvitruk,項目名稱:buddysearch,代碼行數:21,代碼來源:LoginPresenter.java

示例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);
}
 
開發者ID:eurosecom,項目名稱:Attendance,代碼行數:22,代碼來源:EmailPasswordActivity.java

示例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);
}
 
開發者ID:jrummyapps,項目名稱:BusyBox,代碼行數:21,代碼來源:MainApp.java

示例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);
        }
    }
}
 
開發者ID:DevHugo,項目名稱:commitstrip-reader,代碼行數:19,代碼來源:SettingsFragment.java

示例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);
    }
}
 
開發者ID:DevHugo,項目名稱:commitstrip-reader,代碼行數:19,代碼來源:IntroActivity.java

示例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();
}
 
開發者ID:imAKHILc,項目名稱:IEEE_Malabar,代碼行數:22,代碼來源:ActivityMain.java

示例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;
    }
}
 
開發者ID:jamieadkins95,項目名稱:Roach,代碼行數:22,代碼來源:SettingsActivity.java

示例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();
        }
    }
}
 
開發者ID:jamieadkins95,項目名稱:Roach,代碼行數:21,代碼來源:SettingsActivity.java


注:本文中的com.google.firebase.messaging.FirebaseMessaging類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。