本文整理匯總了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);
}