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


Java FirebaseInstanceId類代碼示例

本文整理匯總了Java中com.google.firebase.iid.FirebaseInstanceId的典型用法代碼示例。如果您正苦於以下問題:Java FirebaseInstanceId類的具體用法?Java FirebaseInstanceId怎麽用?Java FirebaseInstanceId使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


FirebaseInstanceId類屬於com.google.firebase.iid包,在下文中一共展示了FirebaseInstanceId類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onHandleIntent

import com.google.firebase.iid.FirebaseInstanceId; //導入依賴的package包/類
@Override
protected void onHandleIntent(Intent intent) {

    FirebaseInstanceId iid = FirebaseInstanceId.getInstance();
    String token = iid.getToken();

    while(token == null){
        iid = FirebaseInstanceId.getInstance();
        token = iid.getToken();
    }


    Intent response = new Intent();
    response.putExtra(TOKEN,token);
    response.setAction(ACTION_TOKEN);
    response.addCategory(Intent.CATEGORY_DEFAULT);
    sendBroadcast(response);


    handleToken(token);
}
 
開發者ID:afiqiqmal,項目名稱:My-Android-Base-Code,代碼行數:22,代碼來源:RegistrationIntentService.java

示例2: onTokenRefresh

import com.google.firebase.iid.FirebaseInstanceId; //導入依賴的package包/類
@Override
public void onTokenRefresh() {

    // Get the saved token from the shared preferences
    final String oldToken = StorageUtils.getStringPref(this, PREF_DEVICE_TOKEN);
    Log.d(getClass().getName(), "Old token: " + oldToken);

    // Get updated InstanceID token
    final String refreshedToken = FirebaseInstanceId.getInstance().getToken();
    Log.d(getClass().getName(), "Refreshed token: " + refreshedToken);

    if (oldToken.isEmpty()) {
        handleNewToken(refreshedToken);
    } else {
        handleTokenUpdate(oldToken, refreshedToken);
    }
}
 
開發者ID:mDL-ILP,項目名稱:mDL-ILP,代碼行數:18,代碼來源:HolderFirebaseInstanceIdService.java

示例3: registerDevice

import com.google.firebase.iid.FirebaseInstanceId; //導入依賴的package包/類
public void registerDevice() {
    if (mDataManager.getPreferencesHelper().getMessagingToken().equals("null")) {
        String token = FirebaseInstanceId.getInstance().getToken();
        Log.d("FirebaseID", "Refreshed token: " + token);

        Log.d("FirebaseID", "sending registration to Server");
        DeviceRequest deviceRequest = new DeviceRequest("firebase", "mobile",
                android.os.Build.MODEL + " (" + android.os.Build.PRODUCT + ")",
                mDataManager.getCurrentUserId(), token, android.os.Build.VERSION.INCREMENTAL);

        RxUtil.unsubscribe(mDevicesSubscription);
        mDevicesSubscription = mDataManager.createDevice(deviceRequest, token)
                .subscribe(
                        deviceResponse -> {},
                        throwable -> {},
                        () -> sendToView(SettingsMvpView::reloadDevices));
    }
}
 
開發者ID:schul-cloud,項目名稱:schulcloud-mobile-android,代碼行數:19,代碼來源:SettingsPresenter.java

示例4: buildRequest

import com.google.firebase.iid.FirebaseInstanceId; //導入依賴的package包/類
/**
 * Create a http request
 * @param method
 * @param endpoint
 * @param body
 * @return
 */
public Request buildRequest(RequestMethod method, String endpoint, RequestBody body) {
    Request.Builder builder = new Request.Builder();
    builder.url(endpoint);
    builder.method(method.getMethod(), body);

    if (DCSession.getInstance().getAuthTokenString() != null)
        builder.addHeader(HEADER_KEY_TOKEN, "Bearer " + DCSession.getInstance().getAuthTokenString());

    String fbmToken = FirebaseInstanceId.getInstance().getToken();
    if (fbmToken != null) {
        builder.addHeader(HEADER_KEY_FBM, fbmToken);
    }

    return builder.build();
}
 
開發者ID:Dentacoin,項目名稱:aftercare-app-android,代碼行數:23,代碼來源:DCApiManager.java

示例5: onTokenRefresh

import com.google.firebase.iid.FirebaseInstanceId; //導入依賴的package包/類
public void onTokenRefresh(final CallbackContext callbackContext) {
    MessagingComponent.tokenRefreshCallbackContext = callbackContext;

    mFirebase.cordova.getThreadPool().execute(new Runnable() {
        public void run() {
            try {
                Log.i(TAG, "Setting onTokenRefresh callback");
                String currentToken = FirebaseInstanceId.getInstance().getToken();

                if (currentToken != null) {
                    MessagingComponent.sendToken(currentToken);
                }
            } catch (Exception e) {
                Log.e(TAG, "Error setting onTokenRefresh callback");
                callbackContext.error(e.getMessage());
            }
        }
    });
}
 
開發者ID:jsayol,項目名稱:cordova-plugin-firebase-sdk,代碼行數:20,代碼來源:MessagingComponent.java

示例6: onTokenRefresh

import com.google.firebase.iid.FirebaseInstanceId; //導入依賴的package包/類
@Override
    public void onTokenRefresh() {
        // Get updated InstanceID token.
        String refreshedToken = FirebaseInstanceId.getInstance().getToken();
        Log.d("TOKEN", "Refreshed token: " + refreshedToken);

        try {
            subscribeTopics(refreshedToken,TOPIC_GLOBAL);
            subscribeTopics(refreshedToken,TOPIC_ESCENARIOS);
            if (BuildConfig.DEBUG) {
                subscribeTopics(refreshedToken, TOPIC_TESTING);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        // If you want to send messages to this application instance or
        // manage this apps subscriptions on the server side, send the
        // Instance ID token to your app server.
//        sendRegistrationToServer(refreshedToken);

    }
 
開發者ID:medialab-prado,項目名稱:puremadrid,代碼行數:23,代碼來源:MyFirebaseInstanceIDService.java

示例7: onCreate

import com.google.firebase.iid.FirebaseInstanceId; //導入依賴的package包/類
@Override
    public void onCreate() {
        super.onCreate();
        Fabric.with(this, new Crashlytics());
        Realm.init(this);
        RealmConfiguration config = new RealmConfiguration.Builder()
                .deleteRealmIfMigrationNeeded().
                        build();
        Realm.setDefaultConfiguration(config);
        FontsOverride.setDefaultFont(this, "DEFAULT", "fonts/questrial_regular.ttf");
//        FontsOverride.setDefaultFont(this, "MONOSPACE", "fonts/quicksand_bold.ttf");
        FontsOverride.setDefaultFont(this, "SERIF", "fonts/quicksand_regular.ttf");
        FontsOverride.setDefaultFont(this, "serif", "fonts/quicksand_regular.ttf");
        FontsOverride.setDefaultFont(this, "arial", "fonts/quicksand_regular.ttf");
//        FontsOverride.setDefaultFont(this, "monospace", "fonts/quicksand_bold.ttf");
        FontsOverride.setDefaultFont(this, "SANS_SERIF", "fonts/quicksand_bold.ttf");

        Logger.d("tokenized");
        try {
            Logger.d(FirebaseInstanceId.getInstance().getToken());
            setUser();
        }catch (Exception e){
            e.printStackTrace();
        }

    }
 
開發者ID:nyangate,項目名稱:Crypto-Assistant,代碼行數:27,代碼來源:CryptoAssistant.java

示例8: onTokenRefresh

import com.google.firebase.iid.FirebaseInstanceId; //導入依賴的package包/類
@Override
public void onTokenRefresh() {
    refreshedToken = FirebaseInstanceId.getInstance().getToken();
    Log.d("reftoken", refreshedToken);
    sharedPreferences = getApplicationContext().getSharedPreferences("event_me", Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.putString("refreshtoken",refreshedToken);
    editor.apply();
    user = FirebaseAuth.getInstance().getCurrentUser();
    if(user != null) {
        userRef = FirebaseDatabase.getInstance().getReference().child(Constants.users).child(Utilities.encodeEmail(user.getEmail()));
        userRef.child("fcmtoken").setValue(refreshedToken);
    }

    // Get updated InstanceID token.

}
 
開發者ID:picopalette,項目名稱:event-me,代碼行數:18,代碼來源:MyFirebaseInstanceIDService.java

示例9: onTokenRefresh

import com.google.firebase.iid.FirebaseInstanceId; //導入依賴的package包/類
@Override public void onTokenRefresh() {
  new Prefs(getApplicationContext());

  String refreshedToken = FirebaseInstanceId.getInstance().getToken();
  Log.d(TAG, "Refreshed token: " + refreshedToken);
  Prefs.saveFCMToken(refreshedToken);

  //Intent i = new Intent("com.humaniq.apilib.fcm.ReceiveNotification");
  //  i.putExtra("registration", "fcm_registered: " + refreshedToken);
  //sendOrderedBroadcast(i, null);

  if(Prefs.hasToken()) {
    try {
      sendRegistrationToServer(refreshedToken);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

}
 
開發者ID:humaniq,項目名稱:react-native-android-library-humaniq-api,代碼行數:21,代碼來源:HumaniqFirebaseInstanceIDService.java

示例10: onTokenRefresh

import com.google.firebase.iid.FirebaseInstanceId; //導入依賴的package包/類
/**
     * Called if InstanceID token is updated. This may occur if the security of
     * the previous token had been compromised. Note that this is also called
     * when the InstanceID token is initially generated, so this is where
     * you retrieve the token.
     */
    // [START refresh_token]
    @Override
    public void onTokenRefresh() {
//        // Get updated InstanceID token.
//        String refreshedToken = FirebaseInstanceId.getInstance().getToken();
//        Log.d("MyInstanceId", "Refreshed token: " + refreshedToken);
//        // TODO: Implement this method to send any registration to your app's servers.
//        sendRegistrationToServer(refreshedToken);

        String refreshedToken = null;
        try {
            refreshedToken = FirebaseInstanceId.getInstance().getToken(Config.fcm_sender_id, "FCM");

            Log.d("MyInstanceId", "sdk:Refreshed token: " + refreshedToken);
            // TODO: Implement this method to send any registration to your app's servers.
            PoleNotificationService.sendRegistrationToServer(refreshedToken, this);

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
 
開發者ID:poletalks,項目名稱:Pole-Beacon-Android-SDK,代碼行數:28,代碼來源:MyInstanceIDListenerService.java

示例11: onTokenRefresh

import com.google.firebase.iid.FirebaseInstanceId; //導入依賴的package包/類
@Override
public void onTokenRefresh() {
    super.onTokenRefresh();
    String refreshedToken = FirebaseInstanceId.getInstance().getToken();

    // Saving reg id to shared preferences
    storeRegIdInPref(refreshedToken);

    // sending reg id to your server
    sendRegistrationToServer(refreshedToken);

    // Notify UI that registration has completed, so the progress indicator can be hidden.
    Intent registrationComplete = new Intent(Config.REGISTRATION_COMPLETE);
    registrationComplete.putExtra("token", refreshedToken);
    LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete);
}
 
開發者ID:safaricom,項目名稱:LNMOnlineAndroidSample,代碼行數:17,代碼來源:MyFirebaseInstanceIDService.java

示例12: sendRegistrationToServer

import com.google.firebase.iid.FirebaseInstanceId; //導入依賴的package包/類
private void sendRegistrationToServer() {
    final FirebaseInstanceId instance = FirebaseInstanceId.getInstance();
    final String instanceId = instance.getId();
    final String instanceToken = instance.getToken();

    Log.d(Utils.LOG_TAG, "Current instanceId is: " + instanceId);
    Log.d(Utils.LOG_TAG, "Current registration id is: " + instanceToken);

    if (instanceToken == null) {
        return;
    }

    WorkContext workContext = RiistaApplication.getInstance().getWorkContext();
    RegisterPushDeviceTask registerPushDeviceTask = new RegisterPushDeviceTask(workContext, instanceToken);
    registerPushDeviceTask.start();
}
 
開發者ID:suomenriistakeskus,項目名稱:oma-riista-android,代碼行數:17,代碼來源:LoginTask.java

示例13: execute

import com.google.firebase.iid.FirebaseInstanceId; //導入依賴的package包/類
@Override
public boolean execute(Message message, Prefs prefs) {
    Long chatId = message.chat().id();
    Prefs.UserPrefs userPrefs = prefs.getUser(message.from().id());
    if (userPrefs != null) {
        StringBuilder result = new StringBuilder();
        result.append(botService.getString(R.string.pro_step_1));
        result.append(botService.getString(R.string.pro_step_2));
        result.append(botService.getString(R.string.pro_step_3));
        result.append(botService.getString(R.string.pro_step_4));


        try {
            String token = FirebaseInstanceId.getInstance().getToken();
            result.append("\nSerial 1: ").append(token).append("\n");
            result.append("\nSerial 2: ").append(Build.SERIAL);
        } catch (Throwable ex) {
            L.e(ex);
        }

        telegramService.sendMessage(chatId, result.toString());
    } else {
        telegramService.sendMessage(chatId, "Incorrect user!");
    }
    return false;
}
 
開發者ID:Rai220,項目名稱:Telephoto,代碼行數:27,代碼來源:ProCommand.java

示例14: onTokenRefresh

import com.google.firebase.iid.FirebaseInstanceId; //導入依賴的package包/類
@Override
public void onTokenRefresh() {

    String refreshedToken = FirebaseInstanceId.getInstance().getToken();

    final Intent intent = new Intent("tokenReceiver");
    // You can also include some extra data.
    final LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(this);
    intent.putExtra("token",refreshedToken);
    broadcastManager.sendBroadcast(intent);


    // Get updated InstanceID token.
    Log.d("Token Is : ", refreshedToken);
    // TODO: Implement this method to send any registration to your app's servers.
 //   sendRegistrationToServer(refreshedToken);
}
 
開發者ID:sciage,項目名稱:FinalProject,代碼行數:18,代碼來源:FCMTokenGenerater.java

示例15: onPostExecute

import com.google.firebase.iid.FirebaseInstanceId; //導入依賴的package包/類
@Override
protected void onPostExecute(String result) {
    if (!result.isEmpty() && APIDecoder.extractStatus(result) != 2) {
        Content.articles = APIDecoder.extractArticles(result);
        APICore.getInstance().write(ctx, APIConstants.CORE_ARTICLES, result);

        Collections.sort(Content.articles, new Comparator<Article>() {
            public int compare(Article a1, Article a2) {
                return a2.getDate().compareTo(a1.getDate());
            }
        });
        articlesAdapter.notifyDataSetChanged();
        APIConstants.ARTICLES_LOADED = true;

        FirebaseApp.initializeApp(ctx);
        APIClient.RegisterNotification registerNotification = new APIClient.RegisterNotification(ctx,
                FirebaseInstanceId.getInstance().getToken());
        registerNotification.execute();
    }
}
 
開發者ID:Snooze986,項目名稱:SonoESEO-Android,代碼行數:21,代碼來源:ArticlesFragment.java


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