当前位置: 首页>>代码示例>>Java>>正文


Java GoogleCloudMessaging类代码示例

本文整理汇总了Java中com.google.android.gms.gcm.GoogleCloudMessaging的典型用法代码示例。如果您正苦于以下问题:Java GoogleCloudMessaging类的具体用法?Java GoogleCloudMessaging怎么用?Java GoogleCloudMessaging使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


GoogleCloudMessaging类属于com.google.android.gms.gcm包,在下文中一共展示了GoogleCloudMessaging类的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);
  }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:22,代码来源:GcmBroadcastReceiver.java

示例2: doInBackground

import com.google.android.gms.gcm.GoogleCloudMessaging; //导入依赖的package包/类
@Override
protected Integer doInBackground(Void... params) {
  try {
    Context                     context        = getActivity();
    SignalServiceAccountManager accountManager = AccountManagerFactory.createManager(context);

    try {
      accountManager.setGcmId(Optional.<String>absent());
    } catch (AuthorizationFailedException e) {
      Log.w(TAG, e);
    }

    if (!TextSecurePreferences.isGcmDisabled(context)) {
      GoogleCloudMessaging.getInstance(context).unregister();
    }

    return SUCCESS;
  } catch (IOException ioe) {
    Log.w(TAG, ioe);
    return NETWORK_ERROR;
  }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:23,代码来源:AdvancedPreferenceFragment.java

示例3: onRun

import com.google.android.gms.gcm.GoogleCloudMessaging; //导入依赖的package包/类
@Override
public void onRun() throws Exception {
  if (TextSecurePreferences.isGcmDisabled(context)) return;

  Log.w(TAG, "Reregistering GCM...");
  int result = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context);

  if (result != ConnectionResult.SUCCESS) {
    notifyGcmFailure();
  } else {
    String gcmId = GoogleCloudMessaging.getInstance(context).register(REGISTRATION_ID);
    textSecureAccountManager.setGcmId(Optional.of(gcmId));

    TextSecurePreferences.setGcmRegistrationId(context, gcmId);
    TextSecurePreferences.setWebsocketRegistered(context, true);
  }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:18,代码来源:GcmRefreshJob.java

示例4: onHandleIntent

import com.google.android.gms.gcm.GoogleCloudMessaging; //导入依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
    Log.d(TAG,"GCMRegistrationService: onHandleIntent()");
    try {
        InstanceID instanceID = InstanceID.getInstance(this);
        int gcmSenderIDIdentifier = getResources().getIdentifier("gcm_sender_id", "string", getPackageName());
        String gcmSenderId = getString(gcmSenderIDIdentifier);
        Log.d(TAG, "GCM Sender ID: " + gcmSenderId);
        String token = instanceID.getToken(gcmSenderId,
                GoogleCloudMessaging.INSTANCE_ID_SCOPE,
                null);
        Log.d(TAG, "Retrieved GCM Token: " + token);
        sendGCMTokenToActivity(token);
    } catch (Exception e) {
        /*
         * If we are unable to retrieve the GCM token we notify the Plugin
         * letting the user know this step failed.
         */
        Log.e(TAG, "Failed to retrieve GCM token", e);
        sendGCMTokenToActivity(null);
    }
}
 
开发者ID:jefflinwood,项目名称:twilio-voice-phonegap-plugin,代码行数:23,代码来源:GCMRegistrationService.java

示例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);

    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);
}
 
开发者ID:rctl,项目名称:CryptoVoice,代码行数:27,代码来源:GcmIntentService.java

示例6: 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);
    }
}
 
开发者ID:jpuderer,项目名称:GarageDoor,代码行数:27,代码来源:GarageDoorIntentService.java

示例7: onHandleIntent

import com.google.android.gms.gcm.GoogleCloudMessaging; //导入依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    try {
        InstanceID instanceID = InstanceID.getInstance(this);
        String token = instanceID.getToken(GarageDoorWidgetProvider.GCM_SENDER_ID,
                GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
        Log.i(TAG, "GCM Registration Token: " + token);

        sendRegistrationToServer(token);

        // You should store a boolean that indicates whether the generated token has been
        // sent to your server. If the boolean is false, send the token to your server,
        // otherwise your server should have already received the token.
        sharedPreferences.edit().putBoolean(GarageDoorWidgetProvider.PREF_SENT_TOKEN_TO_SERVER, true).apply();
    } catch (Exception e) {
        Log.d(TAG, "Failed to complete token refresh", e);
        // If an exception happens while fetching the new token or updating our registration data
        // on a third-party server, this ensures that we'll attempt the update at a later time.
        sharedPreferences.edit().putBoolean(GarageDoorWidgetProvider.PREF_SENT_TOKEN_TO_SERVER, false).apply();
    }
    // Notify UI that registration has completed, so the progress indicator can be hidden.
    Intent registrationComplete = new Intent(GarageDoorWidgetProvider.PREF_REGISTRATION_COMPLETE);
    LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete);
}
 
开发者ID:jpuderer,项目名称:GarageDoor,代码行数:26,代码来源:RegistrationIntentService.java

示例8: onHandleIntent

import com.google.android.gms.gcm.GoogleCloudMessaging; //导入依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    try {
        synchronized (TAG) {
            InstanceID instanceID = InstanceID.getInstance(this);
            String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId),
                    GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
            Log.i(TAG, "GCM Registration Token: " + token);
            sharedPreferences.edit().putString(Preferences.TOKEN, token).apply();
        }
    } catch (Exception e) {
        Log.d(TAG, "Failed to complete token refresh", e);
        //sharedPreferences.edit().putBoolean(Preferences.SENT_TOKEN_TO_SERVER, false).apply();
    }
    // Notify UI that registration has completed, so the progress indicator can be hidden.
    Intent registrationComplete = new Intent(Preferences.REGISTRATION_COMPLETE);
    LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete);
}
 
开发者ID:kflauri2312lffds,项目名称:Android_watch_magpie,代码行数:21,代码来源:RegistrationIntentService.java

示例9: deleteRegistrationToken

import com.google.android.gms.gcm.GoogleCloudMessaging; //导入依赖的package包/类
/**
 * Deletes the current registration token.
 *
 * @param instanceId The instance ID which generated the registration token.
 * @param senderId   The sender ID to revoke the registration token from.
 * @return A task that can be resolved upon deletion of the token.
 */
private Task<Void> deleteRegistrationToken(final InstanceID instanceId, final String senderId) {
    final TaskCompletionSource<Void> future = new TaskCompletionSource<>();
    new AsyncTask<Object, Integer, String>() {
        @Override
        protected String doInBackground(final Object[] ignored) {

            try {
                instanceId.deleteToken(senderId, GoogleCloudMessaging.INSTANCE_ID_SCOPE);
            } catch (final IOException e) {
                Log.e(TAG, "Error deleting GCM registration token", e);
                future.setException(e);
                return null;
            }

            future.setResult(null);
            return null;
        }
    }.execute();

    return future.getTask();
}
 
开发者ID:mongodb,项目名称:stitch-android-sdk,代码行数:29,代码来源:GCMPushClient.java

示例10: getRegistrationToken

import com.google.android.gms.gcm.GoogleCloudMessaging; //导入依赖的package包/类
/**
 * Gets or creates a registration token.
 *
 * @param instanceId The instance ID which should generate the registration token.
 * @param senderId   The sender ID to generate the registration token for.
 * @return A task that can be resolved upon creating/retrieval of the token.
 */
private Task<String> getRegistrationToken(final InstanceID instanceId, final String senderId) {
    final TaskCompletionSource<String> future = new TaskCompletionSource<>();
    new AsyncTask<Object, Integer, String>() {
        @Override
        protected String doInBackground(final Object[] ignored) {

            final String registrationToken;
            try {
                registrationToken = instanceId.getToken(senderId, GoogleCloudMessaging.INSTANCE_ID_SCOPE);
            } catch (final IOException e) {
                Log.e(TAG, "Error getting GCM registration token", e);
                future.setException(e);
                return null;
            }

            future.setResult(registrationToken);
            return null;
        }
    }.execute();

    return future.getTask();
}
 
开发者ID:mongodb,项目名称:stitch-android-sdk,代码行数:30,代码来源:GCMPushClient.java

示例11: 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();
        }
    }
}
 
开发者ID:tiberiusteng,项目名称:financisto1-holo,代码行数:17,代码来源:GCMIntentService.java

示例12: onHandleIntent

import com.google.android.gms.gcm.GoogleCloudMessaging; //导入依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {

    String deviceId = intent.getStringExtra("DEVICE_ID");
    String deviceName = intent.getStringExtra("DEVICE_NAME");

    try {
        InstanceID instanceID = InstanceID.getInstance(this);
        String registrationId = instanceID.getToken(getString(R.string.gcm_defaultSenderId), GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
        registerDeviceProcess(deviceName,deviceId,registrationId);

    } catch (IOException e) {
        e.printStackTrace();
    }

}
 
开发者ID:Learn2Crack,项目名称:android-gcm-client-demo,代码行数:17,代码来源:RegistrationIntentService.java

示例13: 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);
}
 
开发者ID:Turkcell,项目名称:GYAppAnd,代码行数:19,代码来源:PushNotificationIntentService.java

示例14: 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();
       }
    }
}
 
开发者ID:Playtech-EzPush,项目名称:Android-SDK,代码行数:20,代码来源:InteractionRegistration.java

示例15: 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;
}
 
开发者ID:PacktPublishing,项目名称:Asynchronous-Android-Programming,代码行数:25,代码来源:MyBackupService.java


注:本文中的com.google.android.gms.gcm.GoogleCloudMessaging类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。