本文整理了Java中android.os.Messenger
类的一些代码示例,展示了Messenger
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Messenger
类的具体详情如下:
包路径:android.os.Messenger
类名称:Messenger
暂无
代码示例来源:origin: stackoverflow.com
intent = new Intent(this, BTService.class);
Messenger messenger = new Messenger(myHandler);
intent.putExtra("MESSENGER", messenger);
代码示例来源:origin: guardianproject/haven
message.getData().putString("path", fileImage.getAbsolutePath());
serviceMessenger.send(message);
this.context.bindService(new Intent(context,
MonitorService.class), mConnection, Context.BIND_ABOVE_CLIENT);
代码示例来源:origin: firebase/firebase-jobdispatcher-android
@Nullable
@Override
public IBinder onBind(Intent intent) {
// Only Lollipop+ supports UID checking messages, so we can't trust this system on older
// platforms.
if (intent == null
|| Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP
|| !ACTION_EXECUTE.equals(intent.getAction())) {
return null;
}
return getServiceMessenger().getBinder();
}
代码示例来源:origin: stackoverflow.com
public class MessengerService extends Service {
/** Command to the service to display a message */
static final int MSG_SAY_HELLO = 1;
/**
* Handler of incoming messages from clients.
*/
class IncomingHandler extends Handler {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case MSG_SAY_HELLO:
Toast.makeText(getApplicationContext(), "hello!", Toast.LENGTH_SHORT).show();
break;
default:
super.handleMessage(msg);
}
}
}
final Messenger mMessenger = new Messenger(new IncomingHandler());
@Override
public IBinder onBind(Intent intent) {
Toast.makeText(getApplicationContext(), "binding", Toast.LENGTH_SHORT).show();
return mMessenger.getBinder();
}
}
代码示例来源:origin: stackoverflow.com
Messenger messenger = new Messenger(new LocalHandler());
Messenger clientMessenger;
static final int SysterTime = 0;
return messenger.getBinder();
SimpleDateFormat mDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
clientMessenger.send(Message.obtain(null, SysterTime, mDateFormat.format(new Date())));
} catch (RemoteException e) {
e.printStackTrace();
clientMessenger = new Messenger((Handler) msg.obj);
try {
clientMessenger.send(Message.obtain(null, AddHandler, "Registed messanger"));
} catch (RemoteException e) {
e.printStackTrace();
代码示例来源: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
setContentView(R.layout.activity_main);
startActivity(new Intent(this, SecondActivity.class).putExtra(EXTRA_MESSENGER, new Messenger(mHandler)));
代码示例来源:origin: renyuneyun/Easer
@Override
public Void call() throws Exception {
Message message = Message.obtain();
message.what = C.MSG_EDIT_OPERATION_DATA;
message.replyTo = inMessenger;
Bundle bundle = new Bundle();
bundle.putString(C.EXTRA_PLUGIN_ID, id);
//assumes only one EditData is in progress globally, so no MSG_ID is used
message.setData(bundle);
outMessenger.send(message);
return null;
}
};
代码示例来源:origin: stackoverflow.com
messenger.send(message);
} catch (RemoteException e) {
messenger.send(message);
} catch (RemoteException e) {
super.onStart();
bindService(new Intent(this, Server.class), mConnection, BIND_AUTO_CREATE);
代码示例来源:origin: k9mail/k-9
public <T> CancelableBackgroundOperation executeApiAsync(Intent data, OpenPgpDataSource dataSource,
OpenPgpDataSink<T> dataSink, final IOpenPgpSinkResultCallback<T> callback) {
Messenger messenger = new Messenger(new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(Message message) {
callback.onProgress(message.arg1, message.arg2);
return true;
}
}));
data.putExtra(EXTRA_PROGRESS_MESSENGER, messenger);
OpenPgpSourceSinkAsyncTask<T> task = new OpenPgpSourceSinkAsyncTask<>(data, dataSource, dataSink, callback);
// don't serialize async tasks!
// http://commonsware.com/blog/2012/04/20/asynctask-threading-regression-confirmed.html
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void[]) null);
return task;
}
代码示例来源:origin: fg607/RelaxFinger
public void sendMsg(int what, String name, int msg) {
Message message = Message.obtain();
message.what = what;
Bundle bundle = new Bundle();
bundle.putInt(name,msg);
message.setData(bundle);
try {
if(SettingActivity.sMessenger != null){
SettingActivity.sMessenger.send(message);
}
} catch (RemoteException e) {
e.printStackTrace();
}
}
代码示例来源:origin: stackoverflow.com
protected SpeechRecognizer mSpeechRecognizer;
protected Intent mSpeechRecognizerIntent;
protected final Messenger mServerMessenger = new Messenger(new IncomingHandler(this));
mSpeechRecognizer.setRecognitionListener(new SpeechRecognitionListener());
mSpeechRecognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
this.getPackageName());
try
mServerMessenger.send(message);
message = Message.obtain(null, MSG_RECOGNIZER_START_LISTENING);
mServerMessenger.send(message);
try
mServerMessenger.send(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: shkcodes/Lyrically
@Override
protected void onHandleIntent(Intent intent) {
artist = intent.getStringExtra("artist");
track = intent.getStringExtra("track");
songID = intent.getLongExtra("id", 0);
messenger = (Messenger) intent.getExtras().get("messenger");
File path = new File(Environment.getExternalStorageDirectory() + File.separator + "Lyrically/");
notFound = new File(path, "No Lyrics Found.txt");
lyricsFile = new File(path, songID + ".txt");
if (!lyricsFile.exists())
getLyrics();
else
try { // if the text file with the current song ID already exists, skip fetching the lyrics
messenger.send(new Message());
} catch (RemoteException e) {
e.printStackTrace();
}
}
代码示例来源:origin: jksiezni/permissive
static PermissiveFragment create(String[] permissions, Handler handler) {
final PermissiveFragment f = new PermissiveFragment();
final Bundle bundle = new Bundle();
bundle.putStringArray(PERMISSIONS, permissions);
bundle.putParcelable(MESSENGER, new Messenger(handler));
f.setArguments(bundle);
return f;
}
代码示例来源:origin: fg607/RelaxFinger
public void sendMsg(int what, String name, boolean action) {
Message message = Message.obtain();
message.what = what;
Bundle bundle = new Bundle();
bundle.putBoolean(name,action);
message.setData(bundle);
try {
if(SettingActivity.sMessenger != null){
SettingActivity.sMessenger.send(message);
}
} catch (RemoteException e) {
e.printStackTrace();
}
}
代码示例来源:origin: renyuneyun/Easer
@Override
public Void call() throws Exception {
Message message = Message.obtain();
message.what = C.MSG_TRIGGER_OPERATION;
message.getData().putString(C.EXTRA_PLUGIN_ID, id);
message.getData().putParcelable(C.EXTRA_PLUGIN_DATA, data);
try {
outMessenger.send(message);
} catch (RemoteException e) {
e.printStackTrace();
}
return null;
}
};
代码示例来源:origin: stackoverflow.com
@Override
protected void onHandleIntent(Intent intent) {
//your recorder code
//get the messenger from intent
Bundle extras = intent.getExtras();
if (extras != null) {
Messenger messenger = (Messenger) extras.get("MESSENGER");
try {
//send a message back to the activity
messenger.send(...);
} catch (android.os.RemoteException e1) {
Log.w(getClass().getName(), "Exception sending message", e1);
}
}
}
代码示例来源:origin: firebase/firebase-jobdispatcher-android
@Test
public void jobFinished() throws Exception {
final ArgumentCaptor<Message> messageCaptor = ArgumentCaptor.forClass(Message.class);
callback.jobFinished(JobService.RESULT_SUCCESS);
Mockito.verify(messengerMock).send(messageCaptor.capture());
Message message = messageCaptor.getValue();
assertEquals(GooglePlayMessageHandler.MSG_RESULT, message.what);
assertEquals(JobService.RESULT_SUCCESS, message.arg1);
assertEquals("tag", message.getData().getString(REQUEST_PARAM_TAG));
}
}
代码示例来源:origin: stackoverflow.com
Handler myHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
Bundle Recevied = msg.getData();
String resp = Recevied.getString("Mkey");
}
};
messenger = new Messenger(myHandler);
}
内容来源于网络,如有侵权,请联系作者删除!