本文整理汇总了Java中com.google.android.gms.gcm.GoogleCloudMessaging.getInstance方法的典型用法代码示例。如果您正苦于以下问题:Java GoogleCloudMessaging.getInstance方法的具体用法?Java GoogleCloudMessaging.getInstance怎么用?Java GoogleCloudMessaging.getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.android.gms.gcm.GoogleCloudMessaging
的用法示例。
在下文中一共展示了GoogleCloudMessaging.getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onReceive
import com.google.android.gms.gcm.GoogleCloudMessaging; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
String messageType = gcm.getMessageType(intent);
if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
Log.w(TAG, "GCM message...");
if (!TextSecurePreferences.isPushRegistered(context)) {
Log.w(TAG, "Not push registered!");
return;
}
String messageData = intent.getStringExtra("message");
String receiptData = intent.getStringExtra("receipt");
if (!TextUtils.isEmpty(messageData)) handleReceivedMessage(context, messageData);
else if (!TextUtils.isEmpty(receiptData)) handleReceivedMessage(context, receiptData);
else if (intent.hasExtra("notification")) handleReceivedNotification(context);
}
}
示例2: onHandleIntent
import com.google.android.gms.gcm.GoogleCloudMessaging; //导入方法依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
Bundle extras = intent.getExtras();
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
String messageType = gcm.getMessageType(intent);
if (!extras.isEmpty() && GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
Log.w("GCM", extras.toString());
Intent i = new Intent(this, Main.class);// change the context and activity name.
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED +
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD +
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON +
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
this.startActivity(i);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Intent incoming = new Intent("INCOMING");
incoming.putExtra("number", extras.getString("message"));
sendBroadcast(incoming);
}
GcmBroadcastReceiver.completeWakefulIntent(intent);
}
示例3: onHandleIntent
import com.google.android.gms.gcm.GoogleCloudMessaging; //导入方法依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
// Play a click sound and vibrate quickly
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
AudioManager audioManager = (AudioManager)getSystemService(AUDIO_SERVICE);
audioManager.playSoundEffect(SoundEffectConstants.CLICK, 1.0f);
Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
vibrator.vibrate(VIBRATOR_PULSE);
try {
Bundle data = new Bundle();
data.putString("user",
sharedPreferences.getString(GarageDoorWidgetProvider.PREF_USERNAME, ""));
data.putString("password",
sharedPreferences.getString(GarageDoorWidgetProvider.PREF_PASSWORD, ""));
data.putString("timestamp", String.valueOf(System.currentTimeMillis() / 1000));
String id = Integer.toString(getNextMsgId());
gcm.send(GarageDoorWidgetProvider.GCM_SENDER_ID + "@gcm.googleapis.com",
id, TIME_TO_LIVE, data);
} catch (IOException e) {
Log.e(TAG, "Error sending message", e);
}
}
示例4: onHandleIntent
import com.google.android.gms.gcm.GoogleCloudMessaging; //导入方法依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
Bundle extras = intent.getExtras();
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
String messageType = gcm.getMessageType(intent);
if (!extras.isEmpty()) {
if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
if (FlowzrSyncEngine.isRunning) {
Log.i(TAG,"sync already in progess");
return;
}
Log.i(TAG,"starting sync from GCM");
new FlowzrSyncTask(getApplicationContext()).execute();
}
}
}
示例5: onHandleIntent
import com.google.android.gms.gcm.GoogleCloudMessaging; //导入方法依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
Bundle extras = intent.getExtras();
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
String messageType = gcm.getMessageType(intent);
Log.w("PushIntentSerivce", extras.toString());
if (!extras.isEmpty()) {
String from = extras.getString("from");
if (!from.equals("google.com/iid") && GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
createNotification(extras);
}
}
PushNotificationBroadcastReceiver.completeWakefulIntent(intent);
}
示例6: interaction
import com.google.android.gms.gcm.GoogleCloudMessaging; //导入方法依赖的package包/类
@Override
public void interaction() {
gcm = GoogleCloudMessaging.getInstance(context);
if(operationStatus() != StaticFields.STATUS_OK)
{
mJobSheduler = new MJobSheduler(this);
timer = new Timer(true);
timer.schedule(mJobSheduler, 1000, 1000);
}
else
{
if (nextChain != null)
{
nextChain.setSocket(tcpChannel,nextChain.msgHandler);
nextChain.getDataObject().setPushToken(FileUtil.getPushToken(context));
nextChain.interaction();
}
}
}
示例7: onRunTask
import com.google.android.gms.gcm.GoogleCloudMessaging; //导入方法依赖的package包/类
@Override
public int onRunTask(TaskParams taskParams) {
Log.i(TAG, "Backing up the account settings");
final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
Bundle data = new Bundle();
data.putString(FIRST_NAME, sharedPreferences.getString(FIRST_NAME,""));
data.putString(LAST_NAME, sharedPreferences.getString(LAST_NAME,""));
data.putString(AGE, sharedPreferences.getString(AGE,""));
data.putString("resource", RESOURCE);
data.putString("operation", sharedPreferences.getString(OPERATION,""));
String id = Integer.toString(new Random().nextInt());
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(MyBackupService.this);
try {
gcm.send(getString(R.string.gcm_SenderId) + "@gcm.googleapis.com", id, data);
} catch (IOException e) {
Log.e(TAG, "Failed to backup account");
return GcmNetworkManager.RESULT_RESCHEDULE;
}
return GcmNetworkManager.RESULT_SUCCESS;
}
示例8: onHandleIntent
import com.google.android.gms.gcm.GoogleCloudMessaging; //导入方法依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
PDLog.d(GCMIntentService.class, "onHandleIntent");
if (intent == null) {
return;
}
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
String messageType = gcm.getMessageType(intent);
Bundle extras = intent.getExtras();
if (!extras.isEmpty() && messageType.equalsIgnoreCase(GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE)) {
handleMessage(intent);
}
GCMBroadcastReceiver.completeWakefulIntent(intent);
}
示例9: onReceive
import com.google.android.gms.gcm.GoogleCloudMessaging; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
String messageType = gcm.getMessageType(intent);
if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
Log.w(TAG, "GCM message...");
if (!TextSecurePreferences.isPushRegistered(context)) {
Log.w(TAG, "Not push registered!");
return;
}
String messageData = intent.getStringExtra("message");
String receiptData = intent.getStringExtra("receipt");
if (!TextUtils.isEmpty(messageData)) handleReceivedMessage(context, messageData);
else if (!TextUtils.isEmpty(receiptData)) handleReceivedMessage(context, receiptData);
}
}
示例10: onHandleIntent
import com.google.android.gms.gcm.GoogleCloudMessaging; //导入方法依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
Bundle extras = intent.getExtras();
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
String messageType = gcm.getMessageType(intent);
if(!extras.isEmpty()){
if(GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)){
Log.i("GCMIntentService", "Received message");
String details = intent.getStringExtra( "alert" ) ;
String title = intent.getStringExtra( "title" ) ;
String[] location = parseLocation(intent.getStringExtra("location"));
addAlert(title, details, location[1],location[0]);
generateNotification(this,title, details,location[1],location[0]);
}
}
GCMBroadcastReceiver.completeWakefulIntent(intent);
}
示例11: onHandleIntent
import com.google.android.gms.gcm.GoogleCloudMessaging; //导入方法依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
Bundle extras = intent.getExtras();
// GoogleCloudMessagingインスタンスの取得
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
if (gcm != null) {
// GCM受信データを表示
StringBuilder log = new StringBuilder();
log.append("MessageType:").append(gcm.getMessageType(intent));
if (!extras.isEmpty()) {
log.append("\n").append("Extras:").append(extras.toString());
}
Log.d(TAG, log.toString());
}
GcmBroadcastReceiver.completeWakefulIntent(intent);
}
示例12: doInBackground
import com.google.android.gms.gcm.GoogleCloudMessaging; //导入方法依赖的package包/类
@Override
protected String doInBackground(Void... params) {
String msg = "";
try {
if (gcm == null) {
gcm = GoogleCloudMessaging.getInstance(context);
}
regid = gcm.register(SENDER_ID);
msg = "Device registered \n registration ID=" + regid;
sendRegistrationIdToBackend();
storeRegistrationId(context, regid);
} catch (IOException ex) {
msg = "Error :" + ex.getMessage();
}
return msg;
}
示例13: onCreate
import com.google.android.gms.gcm.GoogleCloudMessaging; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initDevice_identifier();
mDisplay = (TextView) findViewById(R.id.tv_display);
context = getApplicationContext();
mQueue = Volley.newRequestQueue(MainActivity.this);
// Check device for Play Services APK. If check succeeds, proceed with
// GCM registration.
if (checkPlayServices()) {
gcm = GoogleCloudMessaging.getInstance(this);
regid = getRegistrationId(context);
if (regid.isEmpty()) {
registerInBackground();
}else{
sendRegistrationIdToBackend();
}
} else {
Log.i(TAG, "No valid Google Play Services APK found.");
}
}
示例14: gcmRegister
import com.google.android.gms.gcm.GoogleCloudMessaging; //导入方法依赖的package包/类
/**
* Get the registrationID from GCM
*
* @param senderID Google Project Sender ID
* @return GCM Registration ID
* @throws IOException
*/
protected String gcmRegister(String senderID) throws IOException {
//TODO: wrap this as an async call?
try {
if (this.gcm == null) {
this.gcm = GoogleCloudMessaging.getInstance(context);
}
Log.d(TAG + "gcmReg", "Attempting to register in gcm for " + senderID);
// Google Play Services may lie. The check in checkPlayServices() may return true even
// if GPS isn't actually present. This will cause the following to generate a null
// pointer exception deep in it's code.
if (true) {
// TODO:: For testing, stub out the actual GCM registration, since it can be
// problematic with the emulators
Log.e(TAG + "gcmReg", "####### STUBBING OUT GCM #########");
return senderID;
}
return this.gcm.register(senderID);
} catch (Exception x) {
// If this fails, presume that GPS is borked and Christmas is ruined, forever.
// If this fails, presume that GPS is borked and Christmas is ruined, forever.
this.gcmFailure = true;
Log.e(TAG + "gcmReg", "GCM Registration failed " + x.toString());
throw new IOException("GCM Registration Failure");
}
}
示例15: registerGCM
import com.google.android.gms.gcm.GoogleCloudMessaging; //导入方法依赖的package包/类
public String registerGCM() {
gcm = GoogleCloudMessaging.getInstance(context);
regId = getRegistrationId(context);
if (TextUtils.isEmpty(regId)) {
registerInBackground();
Log.d("RegisterActivity",
"registerGCM - successfully registered with GCM server - regId: "
+ regId);
} else {
Toast.makeText(context.getApplicationContext(),
"RegId already available. RegId: " + regId,
Toast.LENGTH_LONG).show();
}
return regId;
}