Logcat警告android.app.Notification $ Builder

时间:2014-12-18 18:38:58

标签: android google-drive-api google-play-services

在我的应用中开始使用Google Play服务,突然我开始在我的应用中收到这些警告;

12-18 20:31:50.320: I/dalvikvm(8579): Could not find method android.app.Notification$Builder.setPriority, referenced from method com.google.android.gms.common.GooglePlayServicesUtil.a
12-18 20:31:50.320: W/dalvikvm(8579): VFY: unable to resolve virtual method 230: Landroid/app/Notification$Builder;.setPriority (I)Landroid/app/Notification$Builder;
12-18 20:31:50.320: D/dalvikvm(8579): VFY: replacing opcode 0x6e at 0x0035
12-18 20:31:50.320: D/dalvikvm(8579): DexOpt: unable to opt direct call 0x00cf at 0x3f in Lcom/google/android/gms/common/GooglePlayServicesUtil;.a

我的应用程序的minTarget是16。知道那里发生了什么吗?

1 个答案:

答案 0 :(得分:0)

我厌倦了跟setPriority()的通知代码,它没有问题:

import android.app.Activity;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.TaskStackBuilder;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(this)
                        .setSmallIcon(R.drawable.ic_launcher)
                        .setContentTitle("My notification")
                        .setContentText("Hello World!")
                        .setPriority(5);

// Creates an explicit intent for an Activity in your app
        Intent resultIntent = new Intent(this, MainActivity.class);

// The stack builder object will contain an artificial back stack for the
// started Activity.
// This ensures that navigating backward from the Activity leads out of
// your application to the Home screen.
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
// Adds the back stack for the Intent (but not the Intent itself)
        stackBuilder.addParentStack(MainActivity.class);
// Adds the Intent that starts the Activity to the top of the stack
        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent =
                stackBuilder.getPendingIntent(
                        0,
                        PendingIntent.FLAG_UPDATE_CURRENT
                );
        mBuilder.setContentIntent(resultPendingIntent);
        NotificationManager mNotificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// mId allows you to update the notification later on.
        mNotificationManager.notify(2, mBuilder.build());

    }
 }

会弹出一个简单的通知。

我的build.gradle在app文件夹中:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.myapplication2"
        minSdkVersion 16
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
}