本文整理汇总了Java中android.app.Service类的典型用法代码示例。如果您正苦于以下问题:Java Service类的具体用法?Java Service怎么用?Java Service使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Service类属于android.app包,在下文中一共展示了Service类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onReceive
import android.app.Service; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
TelephonyManager tm = (TelephonyManager) context.getSystemService(Service.TELEPHONY_SERVICE);
switch (tm.getCallState()) {
case TelephonyManager.CALL_STATE_RINGING:
context.startService(new Intent(context, RecordAudioService.class));
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
break;
case TelephonyManager.CALL_STATE_IDLE:
context.stopService(new Intent(context, RecordAudioService.class));
break;
}
}
示例2: onReceive
import android.app.Service; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
WifiManager wifiMgr = (WifiManager) context.getApplicationContext()
.getSystemService(Service.WIFI_SERVICE);
if (wifiMgr.isWifiEnabled()) {
context.startService(new Intent(context, DeskDroidService.class));
} else {
context.stopService(new Intent(context, DeskDroidService.class));
}
}
示例3: handleOnStartOne
import android.app.Service; //导入依赖的package包/类
private void handleOnStartOne(Intent intent, int flags, int startIds) throws Exception {
ServiceInfo info = ApkManager.getInstance().resolveServiceInfo(intent, 0);
if (info != null) {
Service service = (Service) this.mNameService.get(info.name);
if (service != null) {
intent.setExtrasClassLoader(getClassLoader(info.applicationInfo));
Object token = findTokenByService(service);
Integer integer = (Integer) this.mServiceTaskIds.get(token);
if (integer == null) {
integer = Integer.valueOf(-1);
}
int startId = integer.intValue() + 1;
this.mServiceTaskIds.put(token, Integer.valueOf(startId));
int res = service.onStartCommand(intent, flags, startId);
QueuedWorkCompat.waitToFinish();
}
}
}
示例4: createService
import android.app.Service; //导入依赖的package包/类
private static void createService(Service service, Intent intent) {
if (intent.hasExtra(ApkConstant.EXTRA_APK_PATH)) {
String apkPath = ApkComponentModifier.getPath(intent);
String className = ApkComponentModifier.getClassName(intent);
String key = ApkComponentModifier.getKey(intent);
if (!mRealServices.containsKey(service) || !mRealServices.get(service).containsKey(key)) {
try {
Object realToken = new Binder();
Service rawService = handleCreateService(realToken, service, apkPath, className);
if (mRealServices.containsKey(service)) {
mRealServices.get(service).put(key, rawService);
} else {
Map<String, Service> serviceMap = new HashMap<>();
serviceMap.put(key, rawService);
mRealServices.put(service, serviceMap);
}
} catch (Exception e) {
}
}
}
}
示例5: registerApp
import android.app.Service; //导入依赖的package包/类
public final boolean registerApp(String str) {
if (this.detached) {
throw new IllegalStateException("registerApp fail, WXMsgImpl has been detached");
} else if (WXApiImplComm.validateAppSignatureForPackage(this.context, "com.tencent.mm",
this.checkSignature)) {
if (activityCb == null && VERSION.SDK_INT >= 14) {
if (this.context instanceof Activity) {
initMta(this.context, str);
activityCb = new ActivityLifecycleCb(this.context);
((Activity) this.context).getApplication().registerActivityLifecycleCallbacks
(activityCb);
} else if (this.context instanceof Service) {
initMta(this.context, str);
activityCb = new ActivityLifecycleCb(this.context);
((Service) this.context).getApplication().registerActivityLifecycleCallbacks
(activityCb);
} else {
a.b(TAG, "context is not instanceof Activity or Service, disable WXStat");
}
}
a.d(TAG, "registerApp, appId = " + str);
if (str != null) {
this.appId = str;
}
a.d(TAG, "register app " + this.context.getPackageName());
com.tencent.mm.sdk.a.a.a.a aVar = new com.tencent.mm.sdk.a.a.a.a();
aVar.o = "com.tencent.mm";
aVar.p = ConstantsAPI.ACTION_HANDLE_APP_REGISTER;
aVar.m = "weixin://registerapp?appid=" + this.appId;
return com.tencent.mm.sdk.a.a.a.a(this.context, aVar);
} else {
a.a(TAG, "register app failed for wechat app signature check failed");
return false;
}
}
示例6: MediaPlayerImpl
import android.app.Service; //导入依赖的package包/类
public MediaPlayerImpl() {
mMediaPlayer = new MediaPlayer();
// set audio stream type
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mMediaPlayer.setOnBufferingUpdateListener(bufferingUpdateListener);
mMediaPlayer.setOnErrorListener(errorListener);
mMediaPlayer.setOnPreparedListener(preparedListener);
mMediaPlayer.setOnCompletionListener(completionListener);
mMediaPlayer.setOnSeekCompleteListener(seekCompleteListener);
// 不同的音频源,此回调有的不回调!!!
// mMediaPlayer.setOnInfoListener(infoListener);
// 读取音量和静音的数据
currentVolume = (float) MediaPlayerPreferenceUtil.get(context,
KEY_SP_VOLUME, 0.8f);
isMute = (boolean) MediaPlayerPreferenceUtil.get(context,
KEY_SP_MUTE, false);
// LinkedList
mediaPlayerListeners = Collections.synchronizedList(new LinkedList<IMediaPlayer.IMediaPlayerListener>());
posHandler = new PosHandler(Looper.getMainLooper());
// 来电监听
telephonyManager = (TelephonyManager)
context.getSystemService(Service.TELEPHONY_SERVICE);
telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
}
示例7: onStartCommand
import android.app.Service; //导入依赖的package包/类
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d(TAG, "onStartCommand()");
// Create an instance of GoogleAPIClient.
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
mGoogleApiClient.connect();
}
//Reset triggered tasks
SharedPreferenceUtil.setTriggeredTaskList(new ArrayList<Integer>(), getApplicationContext());
//Update Alarms
AlarmManagerUtil.updateAlarms(getApplicationContext());
return Service.START_NOT_STICKY;
}
示例8: onStartCommand
import android.app.Service; //导入依赖的package包/类
public int onStartCommand(Intent intent, int flags, int startId) {
path = intent.getStringExtra("path");
if (path == null) {
stopSelf();
return Service.START_NOT_STICKY;
}
FileLog.e("tmessages", "start video service");
if (builder == null) {
builder = new NotificationCompat.Builder(ApplicationLoader.applicationContext);
builder.setSmallIcon(android.R.drawable.stat_sys_upload);
builder.setWhen(System.currentTimeMillis());
builder.setContentTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setTicker(LocaleController.getString("SendingVideo", R.string.SendingVideo));
builder.setContentText(LocaleController.getString("SendingVideo", R.string.SendingVideo));
}
currentProgress = 0;
builder.setProgress(100, currentProgress, currentProgress == 0);
startForeground(4, builder.build());
NotificationManagerCompat.from(ApplicationLoader.applicationContext).notify(4, builder.build());
return Service.START_NOT_STICKY;
}
示例9: buildNotification
import android.app.Service; //导入依赖的package包/类
private static Notification buildNotification(Service context, String channelId) {
// Create Pending Intents.
PendingIntent piLaunchMainActivity = getLaunchActivityPI(context);
PendingIntent piStopService = getStopServicePI(context);
// Action to stop the service.
Notification.Action stopAction =
new Notification.Action.Builder(
STOP_ACTION_ICON,
getNotificationStopActionText(context),
piStopService)
.build();
// Create a notification.
return new Notification.Builder(context, channelId)
.setContentTitle(getNotificationTitle(context))
.setContentText(getNotificationContent(context))
.setSmallIcon(SMALL_ICON)
.setContentIntent(piLaunchMainActivity)
.setActions(stopAction)
.setStyle(new Notification.BigTextStyle())
.build();
}
示例10: handleOnTaskRemovedOne
import android.app.Service; //导入依赖的package包/类
private void handleOnTaskRemovedOne(Intent intent) throws Exception {
if (VERSION.SDK_INT >= VERSION_CODES.ICE_CREAM_SANDWICH) {
ServiceInfo info = PluginManager.getInstance().resolveServiceInfo(intent, 0);
if (info != null) {
Service service = mNameService.get(info.name);
if (service != null) {
ClassLoader classLoader = getClassLoader(info.applicationInfo);
intent.setExtrasClassLoader(classLoader);
service.onTaskRemoved(intent);
QueuedWorkCompat.waitToFinish();
}
QueuedWorkCompat.waitToFinish();
}
}
}
示例11: onStartCommand
import android.app.Service; //导入依赖的package包/类
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Bundle extras = intent.getExtras();
if (extras != null) {
apkName = extras.getString("name");
downloadUrl = extras.getString("downloadurl");
Logger.i("DownLoadService: %s", apkName + "\r\n" + downloadUrl);
// downloadUrl = "http://pro-app-qn.fir.im/f63088ce552e398521ce5840de798c803b29dd2c.apk?attname=appcloud-v1.0.0-huawei-release.apk_V1.0.0.apk&e=1513073607&token=LOvmia8oXF4xnLh0IdH05XMYpH6ENHNpARlmPc-T:zlbPNpvxSrX779NlvRQW0kTjPr0=";
apkName = apkName + "_" + Long.toString(System.currentTimeMillis() / 1000) + ".apk";
Log.i(TAG, "apkName: " + apkName);
}
//如果路径下apk文件存在,就删除
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), apkName);
if (file.exists()) {
file.delete();
}
//创建广播对象并注册广播,用于监听下载完成后自动安装APK
mReceiver = new DownloadCompleteReceiver();
registerReceiver(mReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
//下载需要写SD卡权限, targetSdkVersion>=23 需要动态申请权限
applyPermissions();
return Service.START_STICKY;
}
示例12: onStartCommand
import android.app.Service; //导入依赖的package包/类
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (BuildConfig.LOG_DEBUG) LogUtils.d(TAG, intent);
boolean isTriggeredAutomatically = isTriggeredAutomatically(intent);
if (intent != null && AppIntent.ACTION_SYNC_START.equals(intent.getAction())) {
if (!isRunning()) {
start(isTriggeredAutomatically);
}
} else if (intent != null && AppIntent.ACTION_SYNC_STOP.equals(intent.getAction())) {
if (isRunning()) {
stop();
}
} else {
if (isRunning()) {
stop();
} else {
start(isTriggeredAutomatically);
}
}
return Service.START_REDELIVER_INTENT;
}
示例13: handleServiceArgs
import android.app.Service; //导入依赖的package包/类
private void handleServiceArgs(Intent serviceIntent,IBinder token){
Service service = mActivateServices.get(token);
if(service!=null){
if(serviceIntent!=null) {
serviceIntent.setExtrasClassLoader(service.getClassLoader());
}
service.onStartCommand(serviceIntent,Service.START_FLAG_RETRY,0);
}
}
示例14: handleOnTaskRemovedOne
import android.app.Service; //导入依赖的package包/类
private void handleOnTaskRemovedOne(Intent intent) throws Exception {
if (VERSION.SDK_INT >= 14) {
ServiceInfo info = ApkManager.getInstance().resolveServiceInfo(intent, 0);
if (info != null) {
Service service = (Service) this.mNameService.get(info.name);
if (service != null) {
intent.setExtrasClassLoader(getClassLoader(info.applicationInfo));
service.onTaskRemoved(intent);
QueuedWorkCompat.waitToFinish();
}
QueuedWorkCompat.waitToFinish();
}
}
}
示例15: handleOnBindOne
import android.app.Service; //导入依赖的package包/类
private IBinder handleOnBindOne(Intent intent) throws Exception {
ServiceInfo info = ApkManager.getInstance().resolveServiceInfo(intent, 0);
if (info != null) {
Service service = (Service) this.mNameService.get(info.name);
if (service != null) {
intent.setExtrasClassLoader(getClassLoader(info.applicationInfo));
return service.onBind(intent);
}
}
return null;
}