本文整理汇总了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);
}
示例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);
}
}
示例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));
}
}
示例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();
}
示例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());
}
}
});
}
示例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);
}
示例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();
}
}
示例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.
}
示例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();
}
}
示例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);
}
示例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();
}
示例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;
}
示例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);
}
示例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();
}
}