本文整理汇总了Java中android.app.PendingIntent.getService方法的典型用法代码示例。如果您正苦于以下问题:Java PendingIntent.getService方法的具体用法?Java PendingIntent.getService怎么用?Java PendingIntent.getService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.app.PendingIntent
的用法示例。
在下文中一共展示了PendingIntent.getService方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setTimeInterval
import android.app.PendingIntent; //导入方法依赖的package包/类
public static void setTimeInterval(Context context){
Log.d(TAG, "Entered set time interval");
Intent selfIntent = getIntent(context);
PendingIntent pendingIntent = PendingIntent.getService(context, 0,
selfIntent, 0);
AlarmManager manager = (AlarmManager) context.getSystemService
(Context.ALARM_SERVICE);
if (isTimeAlarmOn(context)){
manager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.elapsedRealtime(), REPEAT_TIME,
pendingIntent);
Log.d(TAG, "Alarm is not on, starting it now");
}else {
manager.cancel(pendingIntent);
pendingIntent.cancel();
Log.d(TAG, "Alarm is on, cancelling it now");
}
}
示例2: scheduleFeedbackAlarm
import android.app.PendingIntent; //导入方法依赖的package包/类
public void scheduleFeedbackAlarm(final long sessionEnd,
final long alarmOffset, final String sessionTitle) {
// By default, feedback alarms fire 5 minutes before session end time. If alarm offset is
// provided, alarm is set to go off that much time from now (useful for testing).
long alarmTime;
if (alarmOffset == UNDEFINED_ALARM_OFFSET) {
alarmTime = sessionEnd - MILLI_FIVE_MINUTES;
} else {
alarmTime = UIUtils.getCurrentTime(this) + alarmOffset;
}
LOGD(TAG, "Scheduling session feedback alarm for session '" + sessionTitle + "'");
LOGD(TAG, " -> end time: " + sessionEnd + " = " + (new Date(sessionEnd)).toString());
LOGD(TAG, " -> alarm time: " + alarmTime + " = " + (new Date(alarmTime)).toString());
final Intent feedbackIntent = new Intent(
ACTION_NOTIFY_SESSION_FEEDBACK,
null,
this,
SessionAlarmService.class);
PendingIntent pi = PendingIntent.getService(
this, 1, feedbackIntent, PendingIntent.FLAG_CANCEL_CURRENT);
final AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, alarmTime, pi);
}
示例3: onCreate
import android.app.PendingIntent; //导入方法依赖的package包/类
@Override
public void onCreate() {
Log.w("KeyCachingService", "onCreate()");
super.onCreate();
this.pending = PendingIntent.getService(this, 0, new Intent(PASSPHRASE_EXPIRED_EVENT, null,
this, KeyCachingService.class), 0);
if (TextSecurePreferences.isPasswordDisabled(this)) {
try {
MasterSecret masterSecret = MasterSecretUtil.getMasterSecret(this, MasterSecretUtil.UNENCRYPTED_PASSPHRASE);
setMasterSecret(masterSecret);
} catch (InvalidPassphraseException e) {
Log.w("KeyCachingService", e);
}
}
}
示例4: buildForegroundNotification
import android.app.PendingIntent; //导入方法依赖的package包/类
private Notification buildForegroundNotification() {
Intent startService = new Intent(this, LocationService.class);
startService.setAction("START");
PendingIntent startPendingIntent = PendingIntent.getService(this, 0, startService, 0);
Intent stopService = new Intent(this, LocationService.class);
stopService.setAction("STOP");
PendingIntent stopPendingIntent = PendingIntent.getService(this, 0, stopService, 0);
android.support.v7.app.NotificationCompat.Action stopAction =
new NotificationCompat.Action.Builder(R.drawable.ic_stop_black_24dp, getString(R.string.notification_foreground_action_stop_label), stopPendingIntent)
.build();
android.support.v7.app.NotificationCompat.Action startAction =
new NotificationCompat.Action.Builder(R.drawable.ic_play_arrow_black_24dp, getString(R.string.notification_foreground_action_start_label), startPendingIntent)
.build();
return
new android.support.v7.app.NotificationCompat.Builder(this)
.addAction(stopAction)
.addAction(startAction)
.setSmallIcon(android.R.drawable.ic_dialog_info)
.setContentTitle("LocationService")
.setAutoCancel(true)
.setContentText(getString(R.string.service_foregroundNotification_text))
.setStyle(new NotificationCompat.BigTextStyle().bigText(getString(R.string.service_foregroundNotification_bigText)))
.build();
}
示例5: startGeofenceMonitoring
import android.app.PendingIntent; //导入方法依赖的package包/类
public void startGeofenceMonitoring() {
if (googleApiClient.isConnected()) {
for (com.team_htbr.a1617proj1bloeddonatie_app.Location location: locationsList) {
geofences.add(new Geofence.Builder()
.setRequestId(location.getName())
.setCircularRegion(location.getLat(), location.getLng(), 1000)
.setExpirationDuration(Geofence.NEVER_EXPIRE)
.setNotificationResponsiveness(5000)
.setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER)
.build());
}
GeofencingRequest geofencingRequest = new GeofencingRequest.Builder()
.setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER)
.addGeofences(geofences).build();
Intent intent = new Intent(this, GeofenceService.class);
PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
if (!googleApiClient.isConnected()) {
Log.d(TAG, "no connection");
} else {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
LocationServices.GeofencingApi.addGeofences(googleApiClient, geofencingRequest, pendingIntent)
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
if (status.isSuccess()) {
Log.d(TAG, "succesful add");
} else {
Log.d(TAG, "Failed to add");
}
}
});
}
}
}
示例6: initAlarm
import android.app.PendingIntent; //导入方法依赖的package包/类
private void initAlarm(Context context, String serviceName){
if(mAlarmManager == null){
mAlarmManager = ((AlarmManager)context.getSystemService(Context.ALARM_SERVICE));
}
if(mPendingIntent == null){
Intent intent = new Intent();
ComponentName component = new ComponentName(context.getPackageName(), serviceName);
intent.setComponent(component);
intent.setFlags(Intent.FLAG_EXCLUDE_STOPPED_PACKAGES);
mPendingIntent = PendingIntent.getService(context, 0, intent, 0);
}
mAlarmManager.cancel(mPendingIntent);
}
示例7: getServiceNotificationAction
import android.app.PendingIntent; //导入方法依赖的package包/类
private static NotificationCompat.Action getServiceNotificationAction(Context context, String action, int iconResId, int titleResId) {
Intent intent = new Intent(context, WebRtcCallService.class);
intent.setAction(action);
PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, 0);
return new NotificationCompat.Action(iconResId, context.getString(titleResId), pendingIntent);
}
示例8: show
import android.app.PendingIntent; //导入方法依赖的package包/类
public static void show(Context context) {
// Build toggle action
Intent notificationServiceIntent = new Intent(context, NotificationService.class);
notificationServiceIntent.setAction(ACTION_TOGGLE);
PendingIntent notificationPendingIntent = PendingIntent.getService(context, 0, notificationServiceIntent, 0);
NotificationCompat.Action toggleAction = new NotificationCompat.Action(
R.drawable.ic_border_clear_black_24dp,
"Toggle",
notificationPendingIntent
);
// Build notification
NotificationCompat.Builder builder =
new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_zoom_out_map_black_24dp)
.setContentTitle("Immersify")
.setContentText("Tap to toggle immersive mode")
.setContentIntent(notificationPendingIntent)
.setPriority(NotificationCompat.PRIORITY_MIN)
.setCategory(NotificationCompat.CATEGORY_SERVICE)
.addAction(toggleAction)
.setOngoing(true);
// Clear existing notifications
ToggleNotification.cancel(context);
// Notify the notification manager to create the notification
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, builder.build());
}
示例9: onCreate
import android.app.PendingIntent; //导入方法依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
// faz algo algumas vezes
repeat();
PendingIntent pintent =
PendingIntent.getService(this, 0, new Intent(this, ServiceAfterBoot.class), 0);
AlarmManager alarm = (AlarmManager)
getSystemService(Context.ALARM_SERVICE);
alarm.setRepeating(AlarmManager.RTC_WAKEUP,
System.currentTimeMillis() , 60*1000, pintent);
}
示例10: notifyDownloadStart
import android.app.PendingIntent; //导入方法依赖的package包/类
/**
* 开始下载
*
* @param context
* @param title
* @param icon
*/
private void notifyDownloadStart(Context context, Request request)
{
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.api_download_notification);
remoteViews.setProgressBar(R.id.noti_progressBar, PROGRESSBAR_MAX, 0, false);
remoteViews.setImageViewResource(R.id.noti_icon, R.drawable.notification_remote_icon);
remoteViews.setTextViewText(R.id.noti_file_name, request.mTitle);
String host = CommonUtils.getHost(request.mDownloadUrl);
if (CommonUtils.isWo2bHost(request.mDownloadUrl))
{
remoteViews.setTextViewText(R.id.noti_progressBarLeft, "www.wo2b.com");
}
else
{
remoteViews.setTextViewText(R.id.noti_progressBarLeft, host);
}
// 执行取消操作的PendingIntent, 向DownloadService发起取消下载的命令
Intent cancelIntent = new Intent();
cancelIntent.setClass(context, DownloadService.class);
cancelIntent.putExtra(DownloadService.EXTRA_EVENT_TYPE, DownloadService.EVENT_CANCEL);
cancelIntent.putExtra(DownloadService.EXTRA_DOWNLOAD_URL, request.mDownloadUrl);
PendingIntent cancelPendingIntent = PendingIntent.getService(context, 100, cancelIntent,
PendingIntent.FLAG_CANCEL_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.noti_cancel, cancelPendingIntent);
// 消息信息设置
Notification notification = new Notification();
notification.tickerText = request.mTitle;
notification.icon = R.drawable.notification_icon;
notification.contentView = remoteViews;
// notification.flags = Notification.FLAG_AUTO_CANCEL;
notification.flags = Notification.FLAG_ONGOING_EVENT;
// 点击通知栏
Intent intent = new Intent();
intent.setAction("com.wo2b.download.AActivity");
// intent.setClass(context, Download.class);
notification.contentIntent = PendingIntent.getActivity(context, 1, intent, PendingIntent.FLAG_CANCEL_CURRENT);
// 生成通知ID
int notificationId = new Random().nextInt(10000);
mNotificationManager.notify(notificationId, notification);
request.mNotification = notification;
request.mNotificationId = notificationId;
}
示例11: jbNotificationExtras
import android.app.PendingIntent; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void jbNotificationExtras(boolean lowpriority, Notification.Builder builder) { // Notification
try {
if (lowpriority) {
Method setpriority = builder.getClass().getMethod("setPriority", int.class);
// PRIORITY_MIN == -2
setpriority.invoke(builder, -2);
Method setUsesChronometer = builder.getClass().getMethod("setUsesChronometer", boolean.class);
setUsesChronometer.invoke(builder, true);
}
Intent disconnectVPN = new Intent(this, DisconnectVPNActivity.class);
disconnectVPN.setAction(DISCONNECT_VPN);
PendingIntent disconnectPendingIntent = PendingIntent.getActivity(this, 0, disconnectVPN, 0);
builder.addAction(R.drawable.ic_menu_close_clear_cancel, getString(R.string.cancel_connection), disconnectPendingIntent);
Intent pauseVPN = new Intent(this, OpenVPNService.class);
if (mDeviceStateReceiver == null || !mDeviceStateReceiver.isUserPaused()) {
pauseVPN.setAction(PAUSE_VPN);
PendingIntent pauseVPNPending = PendingIntent.getService(this, 0, pauseVPN, 0);
builder.addAction(R.drawable.ic_menu_pause, getString(R.string.pauseVPN), pauseVPNPending);
} else {
pauseVPN.setAction(RESUME_VPN);
PendingIntent resumeVPNPending = PendingIntent.getService(this, 0, pauseVPN, 0);
builder.addAction(R.drawable.ic_menu_play, getString(R.string.resumevpn), resumeVPNPending);
}
//ignore exception
} catch (NoSuchMethodException | IllegalArgumentException | InvocationTargetException | IllegalAccessException e) {
VpnStatus.logException(e);
}
}
示例12: addActionResume
import android.app.PendingIntent; //导入方法依赖的package包/类
private Builder addActionResume(Builder builder) {
Intent pauseIntent = new Intent(getApplicationContext(), this.getClass());
pauseIntent.setAction(ACTION_RESUME);
PendingIntent pausePendingIntent = PendingIntent.getService(getApplicationContext(), 0, pauseIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationBuilderCompatHelper.addAction(builder, getNotificationResources().getResumeActionIcon(), getString(getNotificationResources().getResumeActionText()), pausePendingIntent);
return builder;
}
示例13: onStartCommand
import android.app.PendingIntent; //导入方法依赖的package包/类
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
updateWeather();
updateBingPic();
AlarmManager manager = (AlarmManager) getSystemService(ALARM_SERVICE);
int anHour = 4 * 60 * 60 * 1000;//4个小时的毫秒数
long triggerAtTime = SystemClock.elapsedRealtime() + anHour;
Intent i = new Intent(this, AutoUpdateService.class);
PendingIntent pi = PendingIntent.getService(this, 0, i, 0);
manager.cancel(pi);
manager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerAtTime, pi);
return super.onStartCommand(intent, flags, startId);
}
示例14: startAlarmService
import android.app.PendingIntent; //导入方法依赖的package包/类
/**
* 开启轮询服务
*/
@TargetApi(Build.VERSION_CODES.CUPCAKE)
public static void startAlarmService(Context context, int triggerAtMillis, Class<?> cls, String action) {
Intent intent = new Intent(context, cls);
intent.setAction(action);
PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
startAlarmIntent(context, triggerAtMillis,pendingIntent);
}
示例15: a
import android.app.PendingIntent; //导入方法依赖的package包/类
static /* synthetic */ void a(DownloadService downloadService, int i, c cVar, int i2) {
if (i2 != 0 && !cVar.e()) {
Object obj;
int i3 = 4;
if (2 == i2) {
obj = z[20];
} else if (3 == i2) {
obj = z[18];
} else if (1 == i2) {
String str = z[19];
i3 = 2;
} else {
return;
}
Object obj2 = cVar.s;
Intent intent = new Intent();
if (b.a(i2)) {
intent.setClass(downloadService.getApplicationContext(), DownloadService.class);
cVar.z = -1;
intent.putExtra(z[17], cVar);
}
PendingIntent service = PendingIntent.getService(downloadService, i, intent, 134217728);
if (VERSION.SDK_INT >= 11) {
new Builder(downloadService.getApplicationContext()).setContentTitle(obj2).setContentText(obj).setContentIntent(service).setWhen(System.currentTimeMillis()).setSmallIcon(17301634).getNotification().flags = i3;
} else {
Notification notification = new Notification();
notification.icon = 17301634;
notification.when = System.currentTimeMillis();
notification.flags = i3;
m.a(notification, downloadService.getApplicationContext(), obj2, obj, service);
}
if (downloadService.f != null) {
downloadService.c.notify(i, downloadService.f);
}
}
}