Android 通知在Emulator上工作,但在我的设备上不工作

Android 通知在Emulator上工作,但在我的设备上不工作,android,notifications,deprecated,Android,Notifications,Deprecated,我正在开发一个在API 7及以上版本上运行的应用程序,因此我不得不使用NotificationCompat.Builder而不是Notification,因为它在更高版本中已被弃用。这在emulator上运行良好,但在我的设备上进行测试时,没有任何通知。谁能帮帮我吗。 注:API 7至14不可能只使用API。我想知道,因为我的设备使用API 7,请尝试此功能-它可以在android 2上工作,最多4个: import android.app.Notification; import androi

我正在开发一个在API 7及以上版本上运行的应用程序,因此我不得不使用
NotificationCompat.Builder
而不是Notification,因为它在更高版本中已被弃用。这在emulator上运行良好,但在我的设备上进行测试时,没有任何
通知。谁能帮帮我吗。

注:API 7至14不可能只使用API。我想知道,因为我的设备使用API 7,请尝试此功能-它可以在android 2上工作,最多4个:

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;



    public static void pushNotification(final Context context,
            int icon, String name, String descr, Intent activityIntent) {
        NotificationManager notifyMgr = 
                (NotificationManager)context.getSystemService( 
                Context.NOTIFICATION_SERVICE); 
        long when = System.currentTimeMillis(); 
        PendingIntent pIntent = PendingIntent.getActivity(
                context, 0, activityIntent, 0);
        Notification notification = null;
        if (android.os.Build.VERSION.SDK_INT < 11)
            notification = getNotification8(context, 
                    icon, name, descr, when, pIntent);
        else notification = getNotification11(context, 
                icon, name, descr, when, pIntent);
        notifyMgr.notify(NOTIFY_ID, notification);
    }

    @SuppressWarnings("deprecation")
    private static Notification getNotification8(Context context,
            int icon, String name, String descr, 
            long when, PendingIntent pIntent) {
        Notification notification = new Notification(icon, name, when);
        notification.setLatestEventInfo(context, name, descr, pIntent);
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        return notification;
    }   
    @TargetApi(11)
    private static Notification getNotification11(Context context,
            int icon, String name, String descr, 
            long when, PendingIntent pInten) {
        Notification notification = new Notification.Builder(context)
            .setTicker(name)
            .setContentTitle(name)
            .setContentText(descr)
            .setSmallIcon(icon)
            .setContentIntent(pInten)
            .setAutoCancel(true)
            .setWhen(when)
            .getNotification();     
        return notification;
    }
导入android.app.Notification;
导入android.app.NotificationManager;
导入android.app.pendingent;
公共静态通知(最终上下文,
int图标、字符串名称、字符串描述、意图活动意图){
NotificationManager notifyMgr=
(NotificationManager)上下文。getSystemService(
通知服务);
长时间=System.currentTimeMillis();
PendingEvent pIntent=PendingEvent.getActivity(
上下文,0,活动意图,0);
通知=空;
if(android.os.Build.VERSION.SDK_INT<11)
通知=getNotification8(上下文,
图标、名称、描述、时间、标记);
else通知=getNotification11(上下文,
图标、名称、描述、时间、标记);
notifyMgr.notify(notify_ID,notify);
}
@抑制警告(“弃用”)
私有静态通知getNotification8(上下文,
int图标、字符串名称、字符串描述、,
长时间,下垂的帐篷(小帐篷){
通知通知=新通知(图标、名称、时间);
通知。SetLateStevenInfo(上下文、名称、描述、标题);
notification.flags |=notification.FLAG_AUTO_CANCEL;
退货通知;
}   
@塔吉塔皮(11)
私有静态通知getNotification11(上下文,
int图标、字符串名称、字符串描述、,
长时间,悬挂式帐篷(十针){
通知通知=新建通知.Builder(上下文)
.setTicker(名称)
.setContentTitle(名称)
.setContentText(描述)
.setSmallIcon(图标)
.setContentIntent(pInten)
.setAutoCancel(真)
.setWhen(when)
.getNotification();
退货通知;
}