本文整理汇总了Java中com.google.firebase.iid.FirebaseInstanceId.getToken方法的典型用法代码示例。如果您正苦于以下问题:Java FirebaseInstanceId.getToken方法的具体用法?Java FirebaseInstanceId.getToken怎么用?Java FirebaseInstanceId.getToken使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.firebase.iid.FirebaseInstanceId
的用法示例。
在下文中一共展示了FirebaseInstanceId.getToken方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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();
}
示例3: getToken
import com.google.firebase.iid.FirebaseInstanceId; //导入方法依赖的package包/类
public static String getToken(FirebaseInstanceId firebaseInstanceId, Context context) {
String refreshedToken = null;
try {
refreshedToken = firebaseInstanceId.getToken(Config.fcm_sender_id, "FCM");
Log.d("MyInstanceId", "sdk:Refreshed token: " + refreshedToken);
sendRegistrationToServer(refreshedToken, context);
} catch (IOException e) {
e.printStackTrace();
}
// TODO: Implement this method to send any registration to your app's servers.
return (refreshedToken);
}