Android / Java - 为什么我得到“找不到符号方法startForground”?

时间:2014-07-31 14:04:48

标签: java android methods service

我得到了:

Error:(393, 9) cannot find symbol method startForeground(int,android.app.Notification)

我正在尝试在Foreground中运行我的GPS / Commuting应用程序,以便始终将其视为前台应用程序。这是我的代码片段,我尝试启动前台服务:

@Override
public void onStart() {
    Intent intentForeground = new Intent(this, Activity.class);
    intentForeground.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intentForeground,0);
    pendingIntent.cancel();
    pendingIntent = PendingIntent.getActivity(this, 0, intentForeground,0);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext())
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentIntent(pendingIntent)
            .setContentTitle(getString(R.string.app_name))
            .setContentText("Yup1")
            .setTicker("Yup2")
            .setAutoCancel(false);

    Notification notification = mBuilder.build();
    startForeground(123, notification);
}

我的build.gradle:

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.3"

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:+'
    compile 'com.google.android.gms:play-services:5.0.77+'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.sothree.slidinguppanel:library:+'
    compile 'com.firebase:firebase-client:1.0.16+'
}

0 个答案:

没有答案