Search in sources :

Example 31 with ResultReceiver

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;
}
Also used : Bundle(android.os.Bundle) Intent(android.content.Intent) ResultReceiver(android.os.ResultReceiver)

Example 32 with ResultReceiver

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;
}
Also used : Bundle(android.os.Bundle) Intent(android.content.Intent) ResultReceiver(android.os.ResultReceiver)

Example 33 with ResultReceiver

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);
        }
    }
}
Also used : ResultReceiver(android.os.ResultReceiver)

Example 34 with ResultReceiver

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();
}
Also used : GoogleApiClient(com.google.android.gms.common.api.GoogleApiClient) NotificationManager(android.app.NotificationManager) SharedPreferences(android.content.SharedPreferences) Bundle(android.os.Bundle) ConnectionResult(com.google.android.gms.common.ConnectionResult) Node(com.google.android.gms.wearable.Node) Handler(android.os.Handler) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) RemoteIntent(com.google.android.wearable.intent.RemoteIntent) ResultReceiver(android.os.ResultReceiver)

Example 35 with ResultReceiver

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;
}
Also used : HandlerThread(android.os.HandlerThread) Handler(android.os.Handler) RemoteException(android.os.RemoteException) ResultReceiver(android.os.ResultReceiver)

Aggregations

ResultReceiver (android.os.ResultReceiver)70 Bundle (android.os.Bundle)38 RemoteException (android.os.RemoteException)11 Handler (android.os.Handler)9 HandlerThread (android.os.HandlerThread)6 OnSharedElementsReadyListener (android.app.SharedElementCallback.OnSharedElementsReadyListener)5 Intent (android.content.Intent)5 Parcel (android.os.Parcel)5 Parcelable (android.os.Parcelable)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 JSONArray (org.json.JSONArray)5 JSONException (org.json.JSONException)5 ParcelFileDescriptor (android.os.ParcelFileDescriptor)4 File (java.io.File)4 SharedPreferences (android.content.SharedPreferences)3 IOException (java.io.IOException)3 Point (android.graphics.Point)2 InputMethodManager (android.view.inputmethod.InputMethodManager)2 IResultReceiver (com.android.internal.os.IResultReceiver)2 JSONObject (org.json.JSONObject)2