本文整理了Java中android.os.Message.setData()
方法的一些代码示例,展示了Message.setData()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.setData()
方法的具体详情如下:
包路径:android.os.Message
类名称:Message
方法名:setData
暂无
代码示例来源:origin: cymcsg/UltimateAndroid
/**
* Pushes a message containing bundle onto the end of the message queue after all pending messages before the current time.
*
* @param handler
* @param what
* @param bundle
*/
public static void sendMessageHandler(Handler handler, int what, Bundle bundle) {
Message message = new Message();
message.what = what;
message.setData(bundle);
handler.sendMessage(message);
}
代码示例来源:origin: firebase/firebase-jobdispatcher-android
@NonNull
private Message createResultMessage(int result) {
final Message msg = Message.obtain();
msg.what = GooglePlayMessageHandler.MSG_RESULT;
msg.arg1 = result;
Bundle b = new Bundle();
b.putString(REQUEST_PARAM_TAG, tag);
msg.setData(b);
return msg;
}
}
代码示例来源:origin: mttkay/ignition
protected void notifyImageLoaded(String url, Bitmap bitmap) {
Message message = new Message();
message.what = RemoteImageLoaderHandler.HANDLER_MESSAGE_ID;
Bundle data = new Bundle();
data.putString(RemoteImageLoaderHandler.IMAGE_URL_EXTRA, url);
Bitmap image = bitmap;
data.putParcelable(RemoteImageLoaderHandler.BITMAP_EXTRA, image);
message.setData(data);
handler.sendMessage(message);
}
}
代码示例来源:origin: stackoverflow.com
Bundle bundle = intent.getExtras();
if (bundle != null) {
Messenger messenger = (Messenger) bundle.get("messenger");
Message msg = Message.obtain();
msg.setData(data); //put the data here
try {
messenger.send(msg);
} catch (RemoteException e) {
Log.i("error", "error");
}
}
代码示例来源:origin: cymcsg/UltimateAndroid
/**
* Pushes a message onto the end of the message queue after all pending messages before the current time.
* The message contains what value and a bundle with key and a String value.
* @param handler
* @param what
* @param key
* @param value
*/
public static void sendMessageHandler(Handler handler, int what, String key, String value) {
Message message = new Message();
message.what = what;
Bundle bundle = new Bundle();
bundle.putString(key, value);
message.setData(bundle);
handler.sendMessage(message);
}
代码示例来源:origin: cymcsg/UltimateAndroid
/**
* Pushes a message onto the end of the message queue after all pending messages before the current time.
* The message contains what value and a bundle with key and a int value.
* @param handler
* @param what
* @param key
* @param value
*/
public static void sendMessageHandler(Handler handler, int what, String key, int value) {
Message message = new Message();
message.what = what;
Bundle bundle = new Bundle();
bundle.putInt(key, value);
message.setData(bundle);
handler.sendMessage(message);
}
代码示例来源:origin: ankidroid/Anki-Android
@Override
public Message getDialogHandlerMessage() {
Message msg = Message.obtain();
msg.what = DialogHandler.MSG_SHOW_DATABASE_ERROR_DIALOG;
Bundle b = new Bundle();
b.putInt("dialogType", getArguments().getInt("dialogType"));
msg.setData(b);
return msg;
}
代码示例来源:origin: ankidroid/Anki-Android
@Override
public Message getDialogHandlerMessage() {
Message msg = Message.obtain();
msg.what = DialogHandler.MSG_SHOW_EXPORT_COMPLETE_DIALOG;
Bundle b = new Bundle();
b.putString("exportPath", getArguments().getString("exportPath"));
msg.setData(b);
return msg;
}
}
代码示例来源:origin: ankidroid/Anki-Android
@Override
public Message getDialogHandlerMessage() {
Message msg = Message.obtain();
msg.what = DialogHandler.MSG_SHOW_SYNC_ERROR_DIALOG;
Bundle b = new Bundle();
b.putInt("dialogType", getArguments().getInt("dialogType"));
b.putString("dialogMessage", getArguments().getString("dialogMessage"));
msg.setData(b);
return msg;
}
代码示例来源:origin: cymcsg/UltimateAndroid
/**
* Enqueue a message into the message queue after all pending messages before (current time + delayMillis).
* The message contains what value and a bundle with key and a String value.
* @param handler
* @param what
* @param key
* @param value
* @param delayTime
*/
public static void sendMessageHandlerDelay(Handler handler, int what, String key, String value, long delayTime) {
Message message = new Message();
message.what = what;
Bundle bundle = new Bundle();
bundle.putString(key, value);
message.setData(bundle);
// handler.sendMessage(message);
handler.sendMessageDelayed(message, delayTime);
}
代码示例来源:origin: cymcsg/UltimateAndroid
/**
* Enqueue a message into the message queue after all pending messages before (current time + delayMillis).
* The message contains what value and a bundle with key and a int value.
* @param handler
* @param what
* @param key
* @param value
* @param delayTime
*/
public static void sendMessageHandlerDelay(Handler handler, int what, String key, int value, long delayTime) {
Message message = new Message();
message.what = what;
Bundle bundle = new Bundle();
bundle.putInt(key, value);
message.setData(bundle);
// handler.sendMessage(message);
handler.sendMessageDelayed(message, delayTime);
}
代码示例来源:origin: facebook/facebook-android-sdk
private void sendMessage() {
Bundle data = new Bundle();
data.putString(NativeProtocol.EXTRA_APPLICATION_ID, applicationId);
populateRequestBundle(data);
Message request = Message.obtain(null, requestMessage);
request.arg1 = protocolVersion;
request.setData(data);
request.replyTo = new Messenger(handler);
try {
sender.send(request);
} catch (RemoteException e) {
callback(null);
}
}
代码示例来源:origin: stackoverflow.com
public class DataRequestService extends Service {
private final class ServiceHandler extends Handler {
public ServiceHandler(Looper looper) {
super(looper);
}
@Override
public void handleMessage(Message msg) {
log.info("handleMessage");
//... performing some time-consuming operation
Bundle bundle = msg.getData();
PendingIntent receiver = bundle.getParcelable("receiver");
// Perform the operation associated with PendingIntent
try {
//you can attach data from the operation in the intent.
Intent intent = new Intent();
Bundle b = new Bundle();
//b.putString("key", value);
intent.putExtras(b);
receiver.send(getApplicationContext(), status, intent);
} catch (CanceledException e) {
e.printStackTrace();
}
}
}
@Override
public void onStart(Intent intent, int startId) {
Bundle bundle = intent.getExtras();
msg.setData(bundle);
mServiceHandler.sendMessage(msg);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testGetData() throws Exception {
Message m = new Message();
Bundle b = new Bundle();
m.setData(b);
assertThat(m.getData()).isEqualTo(b);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testPeekData() throws Exception {
assertThat(new Message().peekData()).isNull();
Message m = new Message();
Bundle b = new Bundle();
m.setData(b);
assertThat(m.peekData()).isEqualTo(b);
}
代码示例来源:origin: ankidroid/Anki-Android
@Override
public Message getDialogHandlerMessage() {
Message msg = Message.obtain();
msg.what = DialogHandler.MSG_SHOW_MEDIA_CHECK_COMPLETE_DIALOG;
Bundle b = new Bundle();
b.putStringArrayList("nohave", getArguments().getStringArrayList("nohave"));
b.putStringArrayList("unused", getArguments().getStringArrayList("unused"));
b.putStringArrayList("invalid", getArguments().getStringArrayList("invalid"));
b.putInt("dialogType", getArguments().getInt("dialogType"));
msg.setData(b);
return msg;
}
}
代码示例来源:origin: firebase/firebase-jobdispatcher-android
@Test
public void handleMessage_ignoreIfSenderIsNotGcm() throws Exception {
Message message = Message.obtain();
message.what = GooglePlayMessageHandler.MSG_START_EXEC;
Bundle data = new Bundle();
data.putString(REQUEST_PARAM_TAG, "TAG");
message.setData(data);
message.replyTo = messengerMock;
doThrow(new SecurityException())
.when(appOpsManager)
.checkPackage(message.sendingUid, GooglePlayDriver.BACKEND_PACKAGE);
handler.handleMessage(message);
verify(receiverMock, never()).prepareJob(any(GooglePlayMessengerCallback.class), eq(data));
}
代码示例来源:origin: AltBeacon/android-beacon-library
@TargetApi(18)
private void applyChangesToServices(int type, Region region) throws RemoteException {
if (mScheduledScanJobsEnabled) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
ScanJobScheduler.getInstance().applySettingsToScheduledJob(mContext, this);
}
return;
}
if (serviceMessenger == null) {
throw new RemoteException("The BeaconManager is not bound to the service. Call beaconManager.bind(BeaconConsumer consumer) and wait for a callback to onBeaconServiceConnect()");
}
Message msg = Message.obtain(null, type, 0, 0);
if (type == BeaconService.MSG_SET_SCAN_PERIODS) {
msg.setData(new StartRMData(this.getScanPeriod(), this.getBetweenScanPeriod(), this.mBackgroundMode).toBundle());
}
else if (type == BeaconService.MSG_SYNC_SETTINGS) {
msg.setData(new SettingsData().collect(mContext).toBundle());
}
else {
msg.setData(new StartRMData(region, callbackPackageName(), getScanPeriod(), getBetweenScanPeriod(), mBackgroundMode).toBundle());
}
serviceMessenger.send(msg);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testObtainWithMessage() throws Exception {
Bundle b = new Bundle();
Message m = new Message();
m.arg1 = 10;
m.arg2 = 42;
m.obj = "obj";
m.what = 24;
m.setData(b);
m.setTarget(new Handler());
Message m2 = Message.obtain(m);
assertThat(m2.arg1).isEqualTo(m.arg1);
assertThat(m2.arg2).isEqualTo(m.arg2);
assertThat(m2.obj).isEqualTo(m.obj);
assertThat(m2.what).isEqualTo(m.what);
assertThat(m2.getTarget()).isEqualTo(m.getTarget());
assertThat(m2.getData()).isNotNull();
assertThat(m2.getData().isEmpty()).isTrue();
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testCopyFrom() throws Exception {
Bundle b = new Bundle();
Message m = new Message();
m.arg1 = 10;
m.arg2 = 42;
m.obj = "obj";
m.what = 24;
m.setData(b);
m.setTarget(new Handler());
Message m2 = new Message();
m2.copyFrom(m);
assertThat(m2.arg1).isEqualTo(m.arg1);
assertThat(m2.arg2).isEqualTo(m.arg2);
assertThat(m2.obj).isEqualTo(m.obj);
assertThat(m2.what).isEqualTo(m.what);
assertThat(m2.getTarget()).isNull();
assertThat(m2.getData()).isNotNull();
assertThat(m2.getData().isEmpty()).isTrue();
}
内容来源于网络,如有侵权,请联系作者删除!