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


Java Context.startForegroundService方法代码示例

本文整理汇总了Java中android.content.Context.startForegroundService方法的典型用法代码示例。如果您正苦于以下问题:Java Context.startForegroundService方法的具体用法?Java Context.startForegroundService怎么用?Java Context.startForegroundService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.content.Context的用法示例。


在下文中一共展示了Context.startForegroundService方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: startService

import android.content.Context; //导入方法依赖的package包/类
public static void startService(Context context, Intent intent) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        context.startForegroundService(intent);
    } else {
        context.startService(intent);
    }
}
 
开发者ID:AyushR1,项目名称:KernelAdiutor-Mod,代码行数:8,代码来源:Utils.java

示例2: startService

import android.content.Context; //导入方法依赖的package包/类
private static void startService(Context context, String command) {
    final Intent intent = new Intent(context, MusicService.class);
    intent.setAction(command);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        context.startForegroundService(intent);
    } else {
        context.startService(intent);
    }
}
 
开发者ID:h4h13,项目名称:RetroMusicPlayer,代码行数:10,代码来源:MediaButtonIntentReceiver.java

示例3: startServicePossiblyInForeground

import android.content.Context; //导入方法依赖的package包/类
static void startServicePossiblyInForeground(Context context, Intent i) {
    if (VERSION.SDK_INT >= VERSION_CODES.O) {
        System.out.println(i);
        context.startForegroundService(i);
    } else {
        context.startService(i);
    }
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:9,代码来源:Utils.java

示例4: enablePocketMode

import android.content.Context; //导入方法依赖的package包/类
public void enablePocketMode(Context context, boolean state) {
    sp = context.getSharedPreferences(TAG2, Context.MODE_PRIVATE);
    spe = sp.edit();
    if(state) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            context.startForegroundService(new Intent(context, ProximityService.class));
        } else {
            context.startService(new Intent(context, ProximityService.class));
        }
        spe.putBoolean(TAG,true).apply();
    } else {
        context.stopService(new Intent(context, ProximityService.class));
        spe.putBoolean(TAG,false).apply();
    }
}
 
开发者ID:ShreyanshLodha,项目名称:BlueBolt-Kernel-Tweaking-app,代码行数:16,代码来源:QSTileService.java

示例5: onReceive

import android.content.Context; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
    Log.d(TAG, "Received intent:" + intent);
    // Long running tasks, like calling Account Transfer API, shouldn't happen here. Start a
    // foreground service to perform long running tasks.
    Intent serviceIntent = AccountTransferService.getIntent(context, intent.getAction());
    if (Build.VERSION.SDK_INT >= 26) {
        context.startForegroundService(serviceIntent);
    } else {
        context.startService(serviceIntent);
    }
}
 
开发者ID:googlesamples,项目名称:account-transfer-api,代码行数:13,代码来源:AccountTransferBroadcastReceiver.java

示例6: start

import android.content.Context; //导入方法依赖的package包/类
public static void start(Context context, VpnConfiguration config) {
    Intent intent = new Intent(context, GnirehtetService.class);
    intent.setAction(ACTION_START_VPN);
    intent.putExtra(GnirehtetService.EXTRA_VPN_CONFIGURATION, config);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        context.startForegroundService(intent);
    } else {
        context.startService(intent);
    }
}
 
开发者ID:Genymobile,项目名称:gnirehtet,代码行数:11,代码来源:GnirehtetService.java

示例7: startDownload

import android.content.Context; //导入方法依赖的package包/类
public static void startDownload(@NonNull Context context,
                                 @NonNull HashMap<String, File> downloads) {
    Intent intent = new Intent(context, ModelDownloadService.class);
    intent.putExtra(ARG_DOWNLOAD, downloads);

    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.O) {
        context.startService(intent);
    } else {
        context.startForegroundService(intent);
    }
}
 
开发者ID:kevalpatel2106,项目名称:smart-lens,代码行数:12,代码来源:ModelDownloadService.java

示例8: onReceive

import android.content.Context; //导入方法依赖的package包/类
@Override
public void onReceive(final Context context, Intent intent) {

    // Start service on boot only if the user has said yes in the app.
    final SharedPreferences sp = context.getSharedPreferences(TAG2, Context.MODE_PRIVATE);
    final boolean returnFromSp = sp.getBoolean(TAG2, false);
    if(DEBUG) Log.i(TAG2, String.valueOf(returnFromSp));
    if (returnFromSp) {
        if(DEBUG) Log.d(TAG, "Starting");
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            context.startForegroundService(new Intent(context, ProximityService.class));
        } else {
            context.startService(new Intent(context, ProximityService.class));
        }
    }

    boolean applyOnBoot = sp.getBoolean("ApplyOnBoot",false);
    if(applyOnBoot) {
        final Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                RootUtil r = new RootUtil();
                boolean returnVal = sp.getBoolean("dt2w",false);
                if(returnVal)
                    r.echo(dt2wSysfsNode,"1");
                else
                    r.echo(dt2wSysfsNode,"0");

                returnVal = sp.getBoolean("vdt2w",false);
                if(returnVal)
                    r.echo(vibrateDt2wSysfsNode,"1");
                else
                    r.echo(dt2wSysfsNode,"0");

                returnVal = sp.getBoolean("bcl",false);
                if(DEBUG) Log.i("bcl",String.valueOf(returnVal));
                if(returnVal)
                    r.echo(bclSysfsNode,"-n 'enable'");
                else
                    r.echo(bclSysfsNode,"-n 'disable'");

                r.echo("backlightModeSysfsNode", String.valueOf(sp.getInt("backlightMode",0)));
                r.echo("backlightTimeSysfsNode", String.valueOf(sp.getInt("time",0)));

                Toast.makeText(context, "BKT Boot Settings applied",Toast.LENGTH_SHORT).show();
            }
        },10000);

    }

}
 
开发者ID:ShreyanshLodha,项目名称:BlueBolt-Kernel-Tweaking-app,代码行数:53,代码来源:BootCompleted.java


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