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


Java GoogleCloudMessaging.getInstance方法代码示例

本文整理汇总了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);
  }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:22,代码来源:GcmBroadcastReceiver.java

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

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

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

    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

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

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

示例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);
}
 
开发者ID:Popdeem,项目名称:Popdeem-SDK-Android,代码行数:18,代码来源:GCMIntentService.java

示例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);
  }
}
 
开发者ID:redcracker,项目名称:TextSecure,代码行数:21,代码来源:GcmBroadcastReceiver.java

示例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);
}
 
开发者ID:safesoftware,项目名称:fme-apps-android,代码行数:18,代码来源:GCMIntentService.java

示例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);
}
 
开发者ID:yokmama,项目名称:honki_android,代码行数:17,代码来源:GcmIntentService.java

示例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;
}
 
开发者ID:mirhoseini,项目名称:doostjoo,代码行数:18,代码来源:CloudMessage.java

示例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.");
	}
}
 
开发者ID:xu6148152,项目名称:binea_project_for_android,代码行数:24,代码来源:MainActivity.java

示例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");
  }
}
 
开发者ID:jrconlin,项目名称:mc_backup,代码行数:33,代码来源:GCM.java

示例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;
    }
 
开发者ID:mobile-cloud-computing,项目名称:HybridComputationalOffloading,代码行数:20,代码来源:GCMNotifier.java


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