Android Open Source - RingMyPhoneAndroid Pebble Message Receiver






From Project

Back to project page RingMyPhoneAndroid.

License

The source code is released under:

MIT License

If you think the Android project RingMyPhoneAndroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.darkrockstudios.apps.ringmyphone;
/*ww  w  .  j av  a  2 s .c om*/
import android.content.Context;
import android.content.Intent;
import android.support.v4.content.WakefulBroadcastReceiver;
import android.util.Log;

import com.getpebble.android.kit.Constants;
import com.getpebble.android.kit.PebbleKit;

import java.util.UUID;

/**
 * Created by Adam on 10/14/13.
 */
public class PebbleMessageReceiver extends WakefulBroadcastReceiver
{
  private static final String TAG = PebbleMessageReceiver.class.getSimpleName();

  public void onReceive( final Context context, final Intent intent )
  {
    if( Constants.INTENT_APP_RECEIVE.equals( intent.getAction() ) )
    {
      Log.i( TAG, "Received messaged from Pebble App." );

      final UUID receivedUuid = (UUID) intent.getSerializableExtra( Constants.APP_UUID );
      // Pebble-enabled apps are expected to be good citizens and only inspect broadcasts containing their UUID
      if( !PebbleApp.UUID.equals( receivedUuid ) )
      {
        Log.i( TAG, "not my UUID" );
        return;
      }

      final int transactionId = intent.getIntExtra( Constants.TRANSACTION_ID, -1 );
      final String jsonData = intent.getStringExtra( Constants.MSG_DATA );
      if( jsonData == null || jsonData.isEmpty() )
      {
        Log.w( TAG, "jsonData null" );
        PebbleKit.sendNackToPebble( context, transactionId );
        return;
      }

      Log.w( TAG, "Sending ACK to Pebble. " + transactionId );
      PebbleKit.sendAckToPebble( context, transactionId );

      Log.w( TAG, "Starting RingerService..." );
      Intent serviceIntent = new Intent( context, RingerService.class );
      serviceIntent.putExtra( Constants.TRANSACTION_ID, transactionId );
      serviceIntent.putExtra( Constants.MSG_DATA, jsonData );
      startWakefulService( context, serviceIntent );
    }
  }
}




Java Source Code List

com.darkrockstudios.apps.ringmyphone.AboutFragment.java
com.darkrockstudios.apps.ringmyphone.BillingActivity.java
com.darkrockstudios.apps.ringmyphone.BillingSecurity.java
com.darkrockstudios.apps.ringmyphone.Debug.java
com.darkrockstudios.apps.ringmyphone.MainActivity.java
com.darkrockstudios.apps.ringmyphone.NotificationId.java
com.darkrockstudios.apps.ringmyphone.OsUtil.java
com.darkrockstudios.apps.ringmyphone.PebbleApp.java
com.darkrockstudios.apps.ringmyphone.PebbleMessageReceiver.java
com.darkrockstudios.apps.ringmyphone.PreferencesBackupAgent.java
com.darkrockstudios.apps.ringmyphone.Preferences.java
com.darkrockstudios.apps.ringmyphone.Purchase.java
com.darkrockstudios.apps.ringmyphone.RingerService.java
com.darkrockstudios.apps.ringmyphone.SettingsActivity.java
com.darkrockstudios.apps.ringmyphone.SettingsFragment.java
com.darkrockstudios.apps.ringmyphone.StopRingingReceiver.java
com.darkrockstudios.apps.ringmyphone.UpgradeReceiver.java