本文整理汇总了Java中com.google.android.gms.nearby.messages.Message.getContent方法的典型用法代码示例。如果您正苦于以下问题:Java Message.getContent方法的具体用法?Java Message.getContent怎么用?Java Message.getContent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.android.gms.nearby.messages.Message
的用法示例。
在下文中一共展示了Message.getContent方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: saveFoundMessage
import com.google.android.gms.nearby.messages.Message; //导入方法依赖的package包/类
/**
* Saves a message string to {@link SharedPreferences}.
*
* @param context The context.
* @param message The Message whose payload (as string) is saved to SharedPreferences.
*/
static void saveFoundMessage(Context context, Message message) {
ArrayList<String> cachedMessages = new ArrayList<>(getCachedMessages(context));
Set<String> cachedMessagesSet = new HashSet<>(cachedMessages);
String messageString = new String(message.getContent());
if (!cachedMessagesSet.contains(messageString)) {
cachedMessages.add(0, new String(message.getContent()));
getSharedPreferences(context)
.edit()
.putString(KEY_CACHED_MESSAGES, new Gson().toJson(cachedMessages))
.apply();
}
}
示例2: onFound
import com.google.android.gms.nearby.messages.Message; //导入方法依赖的package包/类
@Override
public void onFound(final Message message) {
String json = new String(message.getContent());
final NearbyPerson person = GSON.fromJson(json, NearbyPerson.class);
runOnUiThread(new Runnable() {
@Override
public void run() {
addPerson(person);
updateList();
}
});
}
示例3: OfferBeacon
import com.google.android.gms.nearby.messages.Message; //导入方法依赖的package包/类
public OfferBeacon(Message message) {
if (!TYPE.equals(message.getType())) {
throw new IllegalArgumentException(
"Incorrect beacon message type: " + message.getType());
}
String json = new String(message.getContent());
try {
JSONObject parsed = new JSONObject(json);
section = parsed.getString("section");
offer = parsed.getString("latest_offer");
} catch (JSONException e) {
throw new IllegalArgumentException("Invalid JSON Contents");
}
}
示例4: onFound
import com.google.android.gms.nearby.messages.Message; //导入方法依赖的package包/类
@Override
public void onFound(Message message) {
String nearbyMessage = new String(message.getContent(), Charset.forName("UTF-8"));
Log.v(TAG, "Found message: " + message.getNamespace());
displayNotification(message);
}
示例5: onLost
import com.google.android.gms.nearby.messages.Message; //导入方法依赖的package包/类
@Override
public void onLost(Message message) {
String nearbyMessage = new String(message.getContent(), Charset.forName("UTF-8"));
Log.v(TAG, "Lost message: " + nearbyMessage);
updateNotification(message);
}
示例6: getView
import com.google.android.gms.nearby.messages.Message; //导入方法依赖的package包/类
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;
if (convertView == null) {
convertView = mInflator.inflate(R.layout.listitem_device, null);
viewHolder = new ViewHolder();
viewHolder.tvAttachment = (TextView) convertView.findViewById(R.id.attachment_message);
viewHolder.tvNamespace = (TextView) convertView.findViewById(R.id.namespace_message);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
Message message = nearbyDeviceMessageList.get(position);
String namespace = message.getNamespace();
final String attachment = new String(message.getContent(), Charset.forName("UTF-8"));
SpannableString attachmentContent = null;
if(attachment.startsWith("http")) {
attachmentContent = new SpannableString(attachment);
attachmentContent.setSpan(new UnderlineSpan(), 0, attachment.length(), 0);
viewHolder.tvAttachment.setText(attachmentContent);
} else {
viewHolder.tvAttachment.setText(attachment);
}
if (namespace != null && namespace.length() > 0)
viewHolder.tvNamespace.setText(namespace);
//viewHolder.projectId.setText(attachment);
if(attachmentContent != null && attachmentContent.toString().startsWith("http")) {
//viewHolder.projectId.setPaintFlags(viewHolder.projectId.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
viewHolder.tvAttachment.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(attachment));
context.startActivity(browserIntent);
}
});
} else {
viewHolder.tvAttachment.setOnClickListener(null);
}
return convertView;
}
开发者ID:NordicSemiconductor,项目名称:Android-nRF-Beacon-for-Eddystone,代码行数:45,代码来源:EddystoneBeaconsAdapter.java