本文整理汇总了Java中com.getpebble.android.kit.util.PebbleDictionary.fromJson方法的典型用法代码示例。如果您正苦于以下问题:Java PebbleDictionary.fromJson方法的具体用法?Java PebbleDictionary.fromJson怎么用?Java PebbleDictionary.fromJson使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.getpebble.android.kit.util.PebbleDictionary
的用法示例。
在下文中一共展示了PebbleDictionary.fromJson方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onReceive
import com.getpebble.android.kit.util.PebbleDictionary; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void onReceive(final Context context, final Intent intent) {
final UUID receivedUuid = (UUID) intent.getSerializableExtra(APP_UUID);
// Pebble-enabled apps are expected to be good citizens and only inspect broadcasts
// containing their UUID
if (!subscribedUuid.equals(receivedUuid)) {
return;
}
final int transactionId = intent.getIntExtra(TRANSACTION_ID, -1);
final String jsonData = intent.getStringExtra(MSG_DATA);
if (jsonData == null || jsonData.isEmpty()) {
return;
}
try {
final PebbleDictionary data = PebbleDictionary.fromJson(jsonData);
receiveData(context, transactionId, data);
} catch (JSONException e) {
e.printStackTrace();
}
}
示例2: onReceive
import com.getpebble.android.kit.util.PebbleDictionary; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void onReceive(final Context context, final Intent intent) {
final UUID receivedUuid = (UUID) intent.getSerializableExtra(APP_UUID);
// Pebble-enabled apps are expected to be good citizens and only inspect broadcasts
// containing their UUID
if (!subscribedUuid.equals(receivedUuid)) {
return;
}
final int transactionId = intent.getIntExtra(TRANSACTION_ID, -1);
final String jsonData = intent.getStringExtra(MSG_DATA);
if (jsonData == null || jsonData.isEmpty()) {
return;
}
try {
final PebbleDictionary data = PebbleDictionary.fromJson(jsonData);
receiveData(context, transactionId, data);
} catch (JSONException e) {
e.printStackTrace();
return;
}
}
示例3: onReceive
import com.getpebble.android.kit.util.PebbleDictionary; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void onReceive(final Context context, final Intent intent) {
final UUID receivedUuid = (UUID) intent.getSerializableExtra(APP_UUID);
// Pebble-enabled apps are expected to be good citizens and only inspect broadcasts containing their UUID
if (!subscribedUuid.equals(receivedUuid)) {
return;
}
final int transactionId = intent.getIntExtra(TRANSACTION_ID, -1);
final String jsonData = intent.getStringExtra(MSG_DATA);
if (jsonData == null || jsonData.isEmpty()) {
return;
}
try {
final PebbleDictionary data = PebbleDictionary.fromJson(jsonData);
receiveData(context, transactionId, data);
} catch (JSONException e) {
e.printStackTrace();
return;
}
}
示例4: onReceive
import com.getpebble.android.kit.util.PebbleDictionary; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
try {
// Intent from Pebble Android app
String json = intent.getStringExtra(Constants.MSG_DATA);
PebbleDictionary dict = PebbleDictionary.fromJson(json);
// Is this a job for Captain Dash API?
if(dict.getInteger(Keys.AppKeyUsesDashAPI) == null) {
return;
}
UUID uuid = (UUID)intent.getSerializableExtra(Constants.APP_UUID);
Log.d(TAG, "Packet received from " + uuid.toString());
// ACK
int transactionId = intent.getIntExtra(TRANSACTION_ID, -1);
PebbleKit.sendAckToPebble(context, transactionId);
// Call Service
Intent i = new Intent(context, Service.class);
i.putExtra("json", json);
i.putExtra("uuid", uuid.toString());
context.startService(i);
} catch(Exception e) {
Log.e(TAG, "Error getting PebbleDictionary from JSON");
e.printStackTrace();
}
}
示例5: onStartCommand
import com.getpebble.android.kit.util.PebbleDictionary; //导入方法依赖的package包/类
@Override
public int onStartCommand( final Intent intent, final int flags, final int startId )
{
if( intent != null )
{
if( ACTION_STOP_RINGING.equals( intent.getAction() ) )
{
silencePhone( this );
}
else
{
if( Purchase.isActive( this ) )
{
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences( this );
final boolean silentMode = settings.getBoolean( Preferences.KEY_SILENT_MODE, false );
final int transactionId = intent.getIntExtra( Constants.TRANSACTION_ID, -1 );
final String jsonData = intent.getStringExtra( Constants.MSG_DATA );
if( jsonData != null )
{
try
{
final long cmd;
final PebbleDictionary data = PebbleDictionary.fromJson( jsonData );
if( data != null )
{
cmd = data.getUnsignedIntegerAsLong( CMD_KEY );
}
else
{
cmd = -1;
}
if( cmd == CMD_START )
{
Log.w( TAG, "Ring Command Received!" );
setMaxVolume( this );
ringPhone( this, silentMode );
}
else if( cmd == CMD_STOP )
{
Log.w( TAG, "Silence Command Received!" );
silencePhone( this );
}
else
{
Log.w( TAG, "Bad command received from pebble app: " + cmd );
}
}
catch( final JSONException e )
{
Log.w( TAG, "failed retrieved -> dict" + e );
}
}
else
{
Log.w( TAG, "No data from Pebble" );
}
}
else
{
postExpiredNotification();
}
}
}
return START_NOT_STICKY;
}