當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。