Created
November 29, 2015 12:55
Revisions
-
Artur-Sulej created this gist
Nov 29, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ public class GcmUtil { public static String getToken(Context context) throws IOException { InstanceID instanceID = InstanceID.getInstance(context); return instanceID.getToken(context.getString(R.string.gcm_defaultSenderId), GoogleCloudMessaging.INSTANCE_ID_SCOPE, null); } public static String getTokenOnThread(final Context context) { try { return new AsyncTask<Void, Void, String>() { @Override protected String doInBackground(Void... params) { try { return getToken(context); } catch (IOException e) { e.printStackTrace(); return null; } } }.execute().get(30L, TimeUnit.SECONDS); } catch (InterruptedException | TimeoutException | ExecutionException e) { e.printStackTrace(); return null; } } }