0
使用Google云消息传递(GCM),PHP和MySQL实现真正移动无线的Android推送通知是任何人都知道的模拟器中的配置手段,设备ID可以轻松地提供给数据库,但在实际设备中如何提供设备ID它不能访问数据库如何输入设备ID到数据库?gcm不适用于真实设备
使用Google云消息传递(GCM),PHP和MySQL实现真正移动无线的Android推送通知是任何人都知道的模拟器中的配置手段,设备ID可以轻松地提供给数据库,但在实际设备中如何提供设备ID它不能访问数据库如何输入设备ID到数据库?gcm不适用于真实设备
只需按照说明书上this page:
明确:
/**
* Main UI for the demo app.
*/
public class DemoActivity extends Activity {
public static final String EXTRA_MESSAGE = "message";
public static final String PROPERTY_REG_ID = "registration_id";
private static final String PROPERTY_APP_VERSION = "appVersion";
private static final String PROPERTY_ON_SERVER_EXPIRATION_TIME =
"onServerExpirationTimeMs";
/**
* Default lifespan (7 days) of a reservation until it is considered expired.
*/
public static final long REGISTRATION_EXPIRY_TIME_MS = 1000 * 3600 * 24 * 7;
/**
* Substitute you own sender ID here.
*/
String SENDER_ID = "Your-Sender-ID";
/**
* Tag used on log messages.
*/
static final String TAG = "GCMDemo";
TextView mDisplay;
GoogleCloudMessaging gcm;
AtomicInteger msgId = new AtomicInteger();
SharedPreferences prefs;
Context context;
String regid;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mDisplay = (TextView) findViewById(R.id.display);
context = getApplicationContext();
regid = getRegistrationId(context);
if (regid.length() == 0) {
registerBackground();
}
gcm = GoogleCloudMessaging.getInstance(this);
}
...
}
请出示所有相关的代码,也是你要确保每个设备真实或仿真器具有设备上的谷歌帐户设置,因为这是gcm正常工作并获取设备ID所需。 –
人们通常遇到模拟器不是真实设备的问题。请记住,该设备必须拥有有效的Google帐户才能使GCM发挥作用。 –