Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
susemi99
committed
Jan 26, 2016
1 parent
a77d170
commit 5463206
Showing
3 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 characters
This file contains 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 characters
43 changes: 43 additions & 0 deletions
43
app/src/main/java/kr/susemi99/gcm/services/RegistrationIntentService.java
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package kr.susemi99.gcm.services; | ||
|
||
import android.app.IntentService; | ||
import android.content.Intent; | ||
import android.support.v4.content.LocalBroadcastManager; | ||
import android.util.Log; | ||
|
||
import com.google.android.gms.gcm.GoogleCloudMessaging; | ||
import com.google.android.gms.iid.InstanceID; | ||
|
||
import java.io.IOException; | ||
|
||
import kr.susemi99.gcm.R; | ||
import kr.susemi99.gcm.managers.PreferenceManager; | ||
|
||
/** | ||
* Created by susemi99 on 2016. 1. 26.. | ||
*/ | ||
public class RegistrationIntentService extends IntentService | ||
{ | ||
public RegistrationIntentService() | ||
{ | ||
super(""); | ||
} | ||
|
||
@Override | ||
protected void onHandleIntent(Intent intent) | ||
{ | ||
InstanceID instanceID = InstanceID.getInstance(this); | ||
try | ||
{ | ||
String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId), GoogleCloudMessaging.INSTANCE_ID_SCOPE, null); | ||
Log.i("RegistrationIntentService | onHandleIntent", "|" + token + "|"); | ||
PreferenceManager.instance(this).sentToken(true); | ||
|
||
Intent registrationCompleteIntent = new Intent(getString(R.string.action_registration_complete)); | ||
LocalBroadcastManager.getInstance(this).sendBroadcast(registrationCompleteIntent); | ||
} catch (IOException e) | ||
{ | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |