本文整理汇总了Java中android.support.v4.os.ResultReceiver类的典型用法代码示例。如果您正苦于以下问题:Java ResultReceiver类的具体用法?Java ResultReceiver怎么用?Java ResultReceiver使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ResultReceiver类属于android.support.v4.os包,在下文中一共展示了ResultReceiver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleMessage
import android.support.v4.os.ResultReceiver; //导入依赖的package包/类
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;
}
}
示例2: getMediaItem
import android.support.v4.os.ResultReceiver; //导入依赖的package包/类
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);
}
});
}
}
示例3: performLoadItem
import android.support.v4.os.ResultReceiver; //导入依赖的package包/类
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);
}
}
示例4: getAudioOnlyDelegateReceiver
import android.support.v4.os.ResultReceiver; //导入依赖的package包/类
private ResultReceiver getAudioOnlyDelegateReceiver() {
return new ResultReceiver(null) {
@Override
protected void onReceiveResult(int resultCode, Bundle resultData) {
Log.d(LOG_TAG, "Received delegate: " + resultCode);
try {
switch (resultCode) {
case PlayerService.DELEGATE_PLAY:
mBufferingView.stop();
showPauseIcon();
break;
case PlayerService.DELEGATE_PAUSE:
showPlayIcon();
break;
case PlayerService.DELEGATE_STOP:
stopAudioOnlyNoServiceCall();
startStreamWithQuality(settings.getPrefStreamQuality());
break;
case PlayerService.DELEGATE_SEEK_TO:
int seekToPosition = resultData.getInt(PlayerService.DELEGATE_SEEK_TO_POSITION);
break;
}
} catch (Exception e) {
e.printStackTrace();
}
}
};
}
示例5: createPlayServiceIntent
import android.support.v4.os.ResultReceiver; //导入依赖的package包/类
public static Intent createPlayServiceIntent(Context context, String url, ChannelInfo channel,
boolean isVod, int vodLength, String vodId, int currentProgress,
Intent activityIntent, ResultReceiver audioOnlyReceiverDelegate) {
Intent playerService = new Intent(context, PlayerService.class);
playerService.putExtra(PlayerService.URL, url);
playerService.putExtra(PlayerService.STREAMER_INFO, channel);
playerService.putExtra(PlayerService.IS_VOD, isVod);
playerService.putExtra(PlayerService.VOD_LENGTH, vodLength);
playerService.putExtra(PlayerService.VOD_ID, vodId);
playerService.putExtra(PlayerService.VOD_PROGRESS, currentProgress);
playerService.putExtra(PlayerService.INTENT, activityIntent);
playerService.putExtra(PlayerService.RECEIVER_DELEGATE, audioOnlyReceiverDelegate);
return playerService;
}
示例6: sendNotification
import android.support.v4.os.ResultReceiver; //导入依赖的package包/类
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);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
PendingIntent pendingIntent = PendingIntent.getActivity(context, REQUEST_CODE_PUSH, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(notificationIcon)
.setContentTitle(notificationTitle)
.setStyle(new NotificationCompat.BigTextStyle().bigText(notificationText))
.setContentText(notificationText)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setPriority(Notification.PRIORITY_HIGH)
.setVibrate(new long[0])
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(requestCode, notificationBuilder.build());
}
示例7: startAction
import android.support.v4.os.ResultReceiver; //导入依赖的package包/类
public static void startAction(Context activity, String postUrl,ResultReceiver receiver)
{
Intent intent = new Intent(activity, FileDownloaderService.class);
Bundle bundle = new Bundle();
bundle.putString(ARGUMENT_FILE_URL, postUrl);
//bundle.putString(ARGUMENT_TARGET_FILE, targetFile);
bundle.putParcelable(ARGUMENT_RESUTL_RECIEVER, receiver);
intent.putExtras(bundle);
activity.startService(intent);
}
示例8: publishProgress
import android.support.v4.os.ResultReceiver; //导入依赖的package包/类
/**
* publish progress to main thread to update progress UI.
*
* @param progress - percent value out of 100.
*/
private void publishProgress(ResultReceiver receiver, int progress)
{
if (receiver != null)
{
Bundle bundle = new Bundle();
bundle.putInt(RESPONSE_DOWNLOAD_PROGRESS, progress);
//bundle.putString(RESPONSE_TYPE,extension);
receiver.send(RESPONSE_CODE_DOWNLOAD_PROGRESS, bundle);
}
}
示例9: newInstance
import android.support.v4.os.ResultReceiver; //导入依赖的package包/类
public static SaveDialog newInstance(ResultReceiver receiver) {
SaveDialog frag = new SaveDialog();
Bundle args = new Bundle();
args.putParcelable("receiver", receiver);
args.putBoolean("isRename", false);
frag.setArguments(args);
return frag;
}
示例10: requestPermissions
import android.support.v4.os.ResultReceiver; //导入依赖的package包/类
/**
* 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());
}
示例11: getMediaItem
import android.support.v4.os.ResultReceiver; //导入依赖的package包/类
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);
}
示例12: registerDelegate
import android.support.v4.os.ResultReceiver; //导入依赖的package包/类
public void registerDelegate(ResultReceiver resultReceiver) {
this.mResultReceiver = resultReceiver;
}
示例13: setReceiver
import android.support.v4.os.ResultReceiver; //导入依赖的package包/类
public void setReceiver(ResultReceiver receiver) {
this.activity = receiver;
}
示例14: onHandleIntent
import android.support.v4.os.ResultReceiver; //导入依赖的package包/类
@Override
protected void onHandleIntent(Intent intent)
{
mContext = getApplicationContext();
dbcon = new DBController(mContext);
instaImage = new InstaImage();
stopDownload = false;
String fileUrl = intent.getStringExtra(ARGUMENT_FILE_URL);
instaImage.set_instaImageURL(fileUrl);
//String targetFile = intent.getStringExtra(ARGUMENT_TARGET_FILE);
ResultReceiver receiver = intent.getParcelableExtra(ARGUMENT_RESUTL_RECIEVER);
String contentType = openConnection(fileUrl);
String outputFilePath = null;
String targetFile="";
String fileName="";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-mm-dd-hh-mm-ss");
File direct = new File(Environment.getExternalStorageDirectory() + "/InstantInsta");
File file=null;
if (!direct.exists()) {
direct = new File(Environment.getExternalStorageDirectory() + "/InstantInsta");
direct.mkdirs();
}
if (contentType == null)
{
outputFilePath = null;
} else if (contentType.contains("image")) {
fileName = "Insta-" + simpleDateFormat.format(new Date()) + ".jpg";
file = new File(direct, fileName);
if (file.exists()) {
file.delete();
// some code to stop duplication
}
instaImage.set_name(fileName);
outputFilePath = downloadImage(file.getAbsolutePath());
//extension = "jpg";
} else {
fileName = "Insta-" + simpleDateFormat.format(new Date()) + ".mp4";
file = new File(direct, fileName);
if (file.exists()) {
file.delete();
// some code to stop duplication
}
instaImage.set_name(fileName);
outputFilePath = downloadFile(file.getAbsolutePath(), receiver);
//extension = "mp4";
}
Bundle bundle = new Bundle();
bundle.putString(RESPONSE_TARGET_FILE, outputFilePath);
bundle.putString(RESPONSE_CAPTION, instaImage.get_caption());
receiver.send(RESPONSE_CODE_DOWNLOAD_RESULT, bundle);
}
示例15: downloadFile
import android.support.v4.os.ResultReceiver; //导入依赖的package包/类
private String downloadFile(String outputFile, ResultReceiver receiver)
{
try
{
File outFile = new File(outputFile);
File tempfile = new File(outputFile + "_temp.pdf");
if (!outFile.getParentFile().exists())
outFile.getParentFile().mkdirs();
FileOutputStream out = new FileOutputStream(tempfile);
long downloaded = 0;
byte[] buffer = new byte[1024];
int len;
while ((len = in.read(buffer)) != -1)
{
downloaded += len;
out.write(buffer, 0, len);
publishProgress(receiver, (int) (((downloaded * 100) / fileSize)));
if (stopDownload)
break;
}
out.flush();
out.close();
if (stopDownload)
tempfile.delete();
else
tempfile.renameTo(outFile);
instaImage.set_phoneImageURL(outputFile);
int id=dbcon.getTotalImages()+1;
instaImage.set_id(id);
dbcon.addimage(instaImage);
in.close();
return outputFile;
} catch (IOException e)
{
e.printStackTrace();
}
return null;
}