我到处搜索但我找不到答案,有没有办法发出简单的HTTP请求?我想在我的某个网站上请求PHP页面/脚本,但我不想显示该网页.
如果可能的话我甚至想在后台(在BroadcastReceiver中)这样做
我打电话给RegistrationIntentService:
if (checkPlayServices()) {
Log.i("udazzT", "check servicies");
// Start IntentService to register this application with GCM.
Intent intent2 = new Intent(this, RegistrationIntentService.class);
startService(intent2);
}
Run Code Online (Sandbox Code Playgroud)
但我在RegistrationIntentService中看不到任何日志:
public class RegistrationIntentService extends IntentService {
private static final String TAG = "RegIntentService";
private static final String[] TOPICS = {"global"};
public RegistrationIntentService() {
super(TAG);
}
@Override
protected void onHandleIntent(Intent intent) {
Log.i("udazzT", "setting token");
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
try {
// In the (unlikely) event that multiple refresh operations occur simultaneously,
// ensure …Run Code Online (Sandbox Code Playgroud) private void registerClient() {
try {
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals("")) {
registrationStatus = "Registering...";
GCMRegistrar.register(this, "1074338555805");
regId = GCMRegistrar.getRegistrationId(this);
registrationStatus = "Registration Acquired";
sendRegistrationToServer();
} else {
registrationStatus = "Already registered";
}
} catch (Exception e) {
e.printStackTrace();
registrationStatus = e.getMessage();
}
}
Run Code Online (Sandbox Code Playgroud)
注册ID从android 2.3.3,2.3.5中的gcm为null但它不是null并且在android 2.3.4,4.0.4中工作.