当前位置: 首页>>代码示例>>Java>>正文


Java Service类代码示例

本文整理汇总了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;
    }
}
 
开发者ID:NaOHAndroid,项目名称:Logistics-guard,代码行数:16,代码来源:PhoneStatReceiver.java

示例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));
    }
}
 
开发者ID:PacktPublishing,项目名称:Java-9-Programming-Blueprints,代码行数:11,代码来源:WifiReceiver.java

示例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();
        }
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:19,代码来源:ServcesManager.java

示例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) {
            }
        }
    }
}
 
开发者ID:LiangMaYong,项目名称:android-apkbox,代码行数:22,代码来源:HookService_Manager.java

示例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;
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:36,代码来源:WXApiImplV10.java

示例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);
}
 
开发者ID:dueros,项目名称:dcs-sdk-java,代码行数:27,代码来源:MediaPlayerImpl.java

示例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;
}
 
开发者ID:abicelis,项目名称:Remindy,代码行数:24,代码来源:NotificationIntentService.java

示例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;
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:22,代码来源:VideoEncodingService.java

示例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();
}
 
开发者ID:r3bl-alliance,项目名称:stay-awake-app,代码行数:24,代码来源:HandleNotifications.java

示例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();
        }
    }
}
 
开发者ID:amikey,项目名称:DroidPlugin,代码行数:16,代码来源:ServcesManager.java

示例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;
    }
 
开发者ID:Jusenr,项目名称:AppFirCloud,代码行数:28,代码来源:DownLoadService.java

示例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;
}
 
开发者ID:orgzly,项目名称:orgzly-android,代码行数:27,代码来源:SyncService.java

示例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);
    }
}
 
开发者ID:alibaba,项目名称:atlas,代码行数:10,代码来源:BaseDelegateService.java

示例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();
        }
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:15,代码来源:ServcesManager.java

示例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;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:12,代码来源:ServcesManager.java


注:本文中的android.app.Service类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。