android.os.Message类的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(580)

本文整理了Java中android.os.Message类的一些代码示例,展示了Message类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message类的具体详情如下:
包路径:android.os.Message
类名称:Message

Message介绍

暂无

代码示例

代码示例来源:origin: google/ExoPlayer

@Override
public void sendMessage(PlayerMessage message) {
 handler.obtainMessage(0, message).sendToTarget();
}

代码示例来源: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: 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 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: guardianproject/haven

@Override
  public void recordingComplete(String path) {
    Message message = new Message();
    message.what = EventTrigger.MICROPHONE;
    message.getData().putString("path",path);
    try {
      if (serviceMessenger != null)
        serviceMessenger.send(message);
    } catch (RemoteException e) {
      // Cannot happen
    }
  }
});

代码示例来源:origin: TommyLemon/APIJSON

Log.d(TAG, "Got decode succeeded message");
state = State.SUCCESS;
Bundle bundle = message.getData();
  (Bitmap) bundle.getParcelable(DecodeThread.BARCODE_BITMAP);//���ñ����߳�
Log.d(TAG, "Got product query message");
String url = (String) message.obj;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
activity.startActivity(intent);

代码示例来源:origin: JZ-Darkal/AndroidHttpCapture

} else if (message.what == R.id.decode_succeeded) {
  state = State.SUCCESS;
  Bundle bundle = message.getData();
  Bitmap barcode = null;
  float scaleFactor = 1.0f;
  if (bundle != null) {
    byte[] compressedBitmap = bundle.getByteArray(DecodeThread.BARCODE_BITMAP);
    if (compressedBitmap != null) {
      barcode = BitmapFactory.decodeByteArray(compressedBitmap, 0, compressedBitmap.length, null);
    scaleFactor = bundle.getFloat(DecodeThread.BARCODE_SCALED_FACTOR);
  String url = (String) message.obj;
  Intent intent = new Intent(Intent.ACTION_VIEW);
  intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
  intent.setData(Uri.parse(url));

代码示例来源: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: 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: stackoverflow.com

Bundle data = message.getData();
intent = new Intent(this, BTService.class);
intent.putExtra("MESSENGER", messenger);

代码示例来源:origin: ankidroid/Anki-Android

if (url.startsWith("playsound:")) {
  Message msg = Message.obtain();
  String soundPath = url.replaceFirst("playsound:", "");
  msg.obj = soundPath;
try {
  if (url.startsWith("intent:")) {
    intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
  } else if (url.startsWith("android-app:")) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) {
      intent = Intent.parseUri(url, 0);
      intent.setData(null);
      intent.setPackage(Uri.parse(url).getHost());
    } else {

代码示例来源:origin: guardianproject/haven

Message message = new Message();
      message.what = EventTrigger.CAMERA;
        message.getData().putString("path", fileImage.getAbsolutePath());
this.context.bindService(new Intent(context,
    MonitorService.class), mConnection, Context.BIND_ABOVE_CLIENT);

代码示例来源: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_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: 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: stackoverflow.com

private class GeocoderHandler extends Handler {
  @Override
  public void handleMessage(Message message) {
    String result;
    switch (message.what) {
    case 1:
      Bundle bundle = message.getData();
      result = bundle.getString("address");
      break;
    default:
      result = null;
    }
    // replace by what you need to do
    myLabel.setText(result);
  }   
}

代码示例来源: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 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 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();
}

代码示例来源: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);
}

相关文章