use of android.os.ResultReceiver in project restful-android by jeremyhaberman.
the class TwitterServiceHelper method getTimeline.
public long getTimeline() {
long requestId = generateRequestID();
requests.put(timelineHashkey, requestId);
ResultReceiver serviceCallback = new ResultReceiver(null) {
@Override
protected void onReceiveResult(int resultCode, Bundle resultData) {
handleGetTimelineResponse(resultCode, resultData);
}
};
Intent intent = new Intent(this.ctx, TwitterService.class);
intent.putExtra(TwitterService.METHOD_EXTRA, TwitterService.METHOD_GET);
intent.putExtra(TwitterService.RESOURCE_TYPE_EXTRA, TwitterService.RESOURCE_TYPE_TIMELINE);
intent.putExtra(TwitterService.SERVICE_CALLBACK, serviceCallback);
intent.putExtra(REQUEST_ID, requestId);
this.ctx.startService(intent);
return requestId;
}
use of android.os.ResultReceiver in project restful-android by jeremyhaberman.
the class TwitterServiceHelper method getProfile.
public long getProfile() {
if (requests.containsKey(profileHashkey)) {
return requests.get(profileHashkey);
}
long requestId = generateRequestID();
requests.put(profileHashkey, requestId);
ResultReceiver serviceCallback = new ResultReceiver(null) {
@Override
protected void onReceiveResult(int resultCode, Bundle resultData) {
handleGetProfileResponse(resultCode, resultData);
}
};
Intent intent = new Intent(this.ctx, TwitterService.class);
intent.putExtra(TwitterService.METHOD_EXTRA, TwitterService.METHOD_GET);
intent.putExtra(TwitterService.RESOURCE_TYPE_EXTRA, TwitterService.RESOURCE_TYPE_PROFILE);
intent.putExtra(TwitterService.SERVICE_CALLBACK, serviceCallback);
intent.putExtra(REQUEST_ID, requestId);
this.ctx.startService(intent);
return requestId;
}
use of android.os.ResultReceiver in project android-delicious by lexs.
the class BookmarkService method onHandleIntent.
@Override
protected void onHandleIntent(Intent intent) {
ResultReceiver receiver = intent.getParcelableExtra(EXTRA_RECEIVER);
if (ACTION_SAVE_BOOKMARK.equals(intent.getAction())) {
String url = intent.getStringExtra(EXTRA_URL);
String title = intent.getStringExtra(EXTRA_TITLE);
String notes = intent.getStringExtra(EXTRA_NOTES);
String tags = intent.getStringExtra(EXTRA_TAGS);
boolean shared = intent.getBooleanExtra(EXTRA_SHARED, true);
boolean success = saveBookmark(url, title, notes, tags, shared);
if (success) {
handler.post(new DisplayToast(this, R.string.toast_bookmark_saved, Toast.LENGTH_SHORT));
receiver.send(RESULT_SUCCESSFULL, null);
} else {
handler.post(new DisplayToast(this, R.string.toast_bookmark_saved_failed, Toast.LENGTH_SHORT));
receiver.send(RESULT_FAILED, null);
}
}
}
use of android.os.ResultReceiver in project muzei by romannurik.
the class ActivateMuzeiIntentService method onHandleIntent.
@Override
protected void onHandleIntent(Intent intent) {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
String action = intent.getAction();
if (TextUtils.equals(action, ACTION_MARK_NOTIFICATION_READ)) {
preferences.edit().putBoolean(ACTIVATE_MUZEI_NOTIF_SHOWN_PREF_KEY, true).apply();
return;
} else if (TextUtils.equals(action, ACTION_REMOTE_INSTALL_MUZEI)) {
Intent remoteIntent = new Intent(Intent.ACTION_VIEW).addCategory(Intent.CATEGORY_BROWSABLE).setData(Uri.parse("market://details?id=" + getPackageName()));
RemoteIntent.startRemoteActivity(this, remoteIntent, new ResultReceiver(new Handler()) {
@Override
protected void onReceiveResult(int resultCode, Bundle resultData) {
if (resultCode == RemoteIntent.RESULT_OK) {
FirebaseAnalytics.getInstance(ActivateMuzeiIntentService.this).logEvent("activate_notif_install_sent", null);
preferences.edit().putBoolean(ACTIVATE_MUZEI_NOTIF_SHOWN_PREF_KEY, true).apply();
} else {
Toast.makeText(ActivateMuzeiIntentService.this, R.string.activate_install_failed, Toast.LENGTH_SHORT).show();
}
}
});
return;
}
// else -> Open on Phone action
GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this).addApi(Wearable.API).build();
ConnectionResult connectionResult = googleApiClient.blockingConnect(30, TimeUnit.SECONDS);
if (!connectionResult.isSuccess()) {
Log.e(TAG, "Failed to connect to GoogleApiClient.");
Toast.makeText(this, R.string.activate_failed, Toast.LENGTH_SHORT).show();
return;
}
Set<Node> nodes = Wearable.CapabilityApi.getCapability(googleApiClient, "activate_muzei", CapabilityApi.FILTER_REACHABLE).await().getCapability().getNodes();
if (nodes.isEmpty()) {
Toast.makeText(this, R.string.activate_failed, Toast.LENGTH_SHORT).show();
} else {
FirebaseAnalytics.getInstance(this).logEvent("activate_notif_message_sent", null);
// Show the open on phone animation
Intent openOnPhoneIntent = new Intent(this, ConfirmationActivity.class);
openOnPhoneIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
openOnPhoneIntent.putExtra(ConfirmationActivity.EXTRA_ANIMATION_TYPE, ConfirmationActivity.OPEN_ON_PHONE_ANIMATION);
startActivity(openOnPhoneIntent);
// Clear the notification
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.cancel(INSTALL_NOTIFICATION_ID);
preferences.edit().putBoolean(ACTIVATE_MUZEI_NOTIF_SHOWN_PREF_KEY, true).apply();
// Send the message to the phone to open Muzei
for (Node node : nodes) {
Wearable.MessageApi.sendMessage(googleApiClient, node.getId(), "notification/open", null).await();
}
}
googleApiClient.disconnect();
}
use of android.os.ResultReceiver in project platform_frameworks_base by android.
the class Pm method runShellCommand.
private int runShellCommand(String serviceName, String[] args) {
final HandlerThread handlerThread = new HandlerThread("results");
handlerThread.start();
try {
ServiceManager.getService(serviceName).shellCommand(FileDescriptor.in, FileDescriptor.out, FileDescriptor.err, args, new ResultReceiver(new Handler(handlerThread.getLooper())));
return 0;
} catch (RemoteException e) {
e.printStackTrace();
} finally {
handlerThread.quitSafely();
}
return -1;
}
Aggregations