【发布时间】:2016-05-22 08:58:15
【问题描述】:
我想将令牌从一个活动传递到另一个活动,但我不知道我能做什么,因为使用 Intent 有问题。
通过这个活动我得到了令牌:
public class RegistrationIntentService extends IntentService {
// abbreviated tag name
static final String TAG = "RegIntentService";
public RegistrationIntentService() {
super(TAG);
}
@Override
protected void onHandleIntent(Intent intent) {
// Make a call to Instance API
InstanceID instanceID = InstanceID.getInstance(this);
String senderId = getResources().getString(R.string.gcm_defaultSenderId);
try {
// request token that will be used by the server to send push notifications
String token = instanceID.getToken(senderId, GoogleCloudMessaging.INSTANCE_ID_SCOPE);
Log.d(TAG, "GCM Registration Token: " + token);
// pass along this data
sendRegistrationToServer(token);
} catch (IOException e) {
e.printStackTrace();
}
}
public void sendRegistrationToServer(String token) {
// Add custom implementation, as needed.
}
}
通过这个活动,我将代码传递到我的服务器中:
public void userLogin(View view){
login_name = ET_NAME.getText().toString();
login_pass = ET_PASS.getText().toString();
String method = "login";
String token = getRegTokenId();
BackgroundTaskLogin backgroundTask = new BackgroundTaskLogin(mContext);
backgroundTask.execute(method, login_name, login_pass, token);
}
private void getRegTokenId(){
Intent intent = new Intent(mContext, RegistrationIntentService.class);
startService(intent);
}
提前致谢。
【问题讨论】:
标签: java android android-intent google-cloud-messaging token