android.support.v4.os.ResultReceiver Java Examples
The following examples show how to use
android.support.v4.os.ResultReceiver.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MediaBrowserServiceCompat.java From letv with Apache License 2.0 | 6 votes |
public void handleMessage(Message msg) { Bundle data = msg.getData(); switch (msg.what) { case 1: this.mServiceImpl.connect(data.getString(MediaBrowserProtocol.DATA_PACKAGE_NAME), data.getInt(MediaBrowserProtocol.DATA_CALLING_UID), data.getBundle(MediaBrowserProtocol.DATA_ROOT_HINTS), new ServiceCallbacksCompat(msg.replyTo)); return; case 2: this.mServiceImpl.disconnect(new ServiceCallbacksCompat(msg.replyTo)); return; case 3: this.mServiceImpl.addSubscription(data.getString(MediaBrowserProtocol.DATA_MEDIA_ITEM_ID), data.getBundle(MediaBrowserProtocol.DATA_OPTIONS), new ServiceCallbacksCompat(msg.replyTo)); return; case 4: this.mServiceImpl.removeSubscription(data.getString(MediaBrowserProtocol.DATA_MEDIA_ITEM_ID), data.getBundle(MediaBrowserProtocol.DATA_OPTIONS), new ServiceCallbacksCompat(msg.replyTo)); return; case 5: this.mServiceImpl.getMediaItem(data.getString(MediaBrowserProtocol.DATA_MEDIA_ITEM_ID), (ResultReceiver) data.getParcelable(MediaBrowserProtocol.DATA_RESULT_RECEIVER)); return; case 6: this.mServiceImpl.registerCallbacks(new ServiceCallbacksCompat(msg.replyTo)); return; default: Log.w(MediaBrowserServiceCompat.TAG, "Unhandled message: " + msg + "\n Service version: " + 1 + "\n Client version: " + msg.arg1); return; } }
Example #2
Source File: MediaBrowserServiceCompat.java From letv with Apache License 2.0 | 5 votes |
public void getMediaItem(final String mediaId, final ResultReceiver receiver) { if (!TextUtils.isEmpty(mediaId) && receiver != null) { MediaBrowserServiceCompat.this.mHandler.postOrRun(new Runnable() { public void run() { MediaBrowserServiceCompat.this.performLoadItem(mediaId, receiver); } }); } }
Example #3
Source File: MediaBrowserServiceCompat.java From letv with Apache License 2.0 | 5 votes |
public void getMediaItem(String mediaId, final ItemCallback cb) { this.mServiceImpl.getMediaItem(mediaId, new ResultReceiver(MediaBrowserServiceCompat.this.mHandler) { protected void onReceiveResult(int resultCode, Bundle resultData) { MediaItem item = (MediaItem) resultData.getParcelable(MediaBrowserServiceCompat.KEY_MEDIA_ITEM); Parcel itemParcel = null; if (item != null) { itemParcel = Parcel.obtain(); item.writeToParcel(itemParcel, 0); } cb.onItemLoaded(resultCode, resultData, itemParcel); } }); }
Example #4
Source File: MediaBrowserServiceCompat.java From letv with Apache License 2.0 | 5 votes |
private void performLoadItem(String itemId, final ResultReceiver receiver) { Result<MediaItem> result = new Result<MediaItem>(itemId) { void onResultSent(MediaItem item, int flag) { Bundle bundle = new Bundle(); bundle.putParcelable(MediaBrowserServiceCompat.KEY_MEDIA_ITEM, item); receiver.send(0, bundle); } }; onLoadItem(itemId, result); if (!result.isDone()) { throw new IllegalStateException("onLoadItem must call detach() or sendResult() before returning for id=" + itemId); } }
Example #5
Source File: PermissionHelper.java From satstat with GNU General Public License v3.0 | 5 votes |
/** * Requests permissions to be granted to this application. * * This method is a wrapper around * {@link android.support.v4.app.ActivityCompat#requestPermissions(android.app.Activity, String[], int)} * which works in a similar way, except it can be called from non-activity contexts. When called, it * displays a notification with a customizable title and text. When the user taps the notification, an * activity is launched in which the user is prompted to allow or deny the request. * * After the user has made a choice, * {@link android.support.v4.app.ActivityCompat.OnRequestPermissionsResultCallback#onRequestPermissionsResult(int, String[], int[])} * is called, reporting whether the permissions were granted or not. * * @param context The context from which the request was made. The context supplied must implement * {@link android.support.v4.app.ActivityCompat.OnRequestPermissionsResultCallback} and will receive the * result of the operation. * @param permissions The requested permissions * @param requestCode Application specific request code to match with a result reported to * {@link android.support.v4.app.ActivityCompat.OnRequestPermissionsResultCallback#onRequestPermissionsResult(int, String[], int[])} * @param notificationTitle The title for the notification * @param notificationText The text for the notification * @param notificationIcon Resource identifier for the notification icon */ public static <T extends Context & OnRequestPermissionsResultCallback> void requestPermissions(final T context, String[] permissions, int requestCode, String notificationTitle, String notificationText, int notificationIcon) { ResultReceiver resultReceiver = new ResultReceiver(new Handler(Looper.getMainLooper())) { @Override protected void onReceiveResult (int resultCode, Bundle resultData) { String[] outPermissions = resultData.getStringArray(Const.KEY_PERMISSIONS); int[] grantResults = resultData.getIntArray(Const.KEY_GRANT_RESULTS); context.onRequestPermissionsResult(resultCode, outPermissions, grantResults); } }; Intent permIntent = new Intent(context, PermissionRequestActivity.class); permIntent.putExtra(Const.KEY_RESULT_RECEIVER, resultReceiver); permIntent.putExtra(Const.KEY_PERMISSIONS, permissions); permIntent.putExtra(Const.KEY_REQUEST_CODE, requestCode); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addNextIntent(permIntent); PendingIntent permPendingIntent = stackBuilder.getPendingIntent( 0, PendingIntent.FLAG_UPDATE_CURRENT ); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setSmallIcon(notificationIcon) .setContentTitle(notificationTitle) .setContentText(notificationText) .setOngoing(true) //.setCategory(Notification.CATEGORY_STATUS) .setAutoCancel(true) .setWhen(0) .setContentIntent(permPendingIntent) .setStyle(null); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(requestCode, builder.build()); }
Example #6
Source File: MediaBrowserCompat.java From letv with Apache License 2.0 | 4 votes |
void getMediaItem(String mediaId, ResultReceiver receiver) throws RemoteException { Bundle data = new Bundle(); data.putString(MediaBrowserProtocol.DATA_MEDIA_ITEM_ID, mediaId); data.putParcelable(MediaBrowserProtocol.DATA_RESULT_RECEIVER, receiver); sendRequest(5, data, null); }
Example #7
Source File: NotificationHelper.java From PermissionEverywhere with Apache License 2.0 | 4 votes |
public static void sendNotification(Context context, String[] permissions, int requestCode, String notificationTitle, String notificationText, int notificationIcon, ResultReceiver receiver) { Intent intent = new Intent(context, PermissionActivity.class); intent.putExtra(Const.REQUEST_CODE, requestCode); intent.putExtra(Const.PERMISSIONS_ARRAY, permissions); intent.putExtra(Const.RESULT_RECEIVER, receiver); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT); } PendingIntent pendingIntent = PendingIntent.getActivity(context, REQUEST_CODE_PUSH, intent, PendingIntent.FLAG_ONE_SHOT); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID, context.getString(R.string.channel_name), NotificationManager.IMPORTANCE_HIGH); notificationChannel.enableLights(true); notificationChannel.setLightColor(Color.RED); notificationChannel.setShowBadge(true); notificationChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC); notificationManager.createNotificationChannel(notificationChannel); } Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, CHANNEL_ID) .setSmallIcon(notificationIcon) .setContentTitle(notificationTitle) .setStyle(new NotificationCompat.BigTextStyle().bigText(notificationText)) .setContentText(notificationText) .setAutoCancel(true) .setSound(defaultSoundUri) .setPriority(NotificationCompat.PRIORITY_HIGH) .setVibrate(new long[0]) .setContentIntent(pendingIntent); notificationManager.notify(requestCode, notificationBuilder.build()); }