Android API上的通知兼容性生成器<;11不工作
上面的代码在我的Nexus4(安卓4.3)上运行得很好,但我的旧NexusOne(安卓2.3.7)仍然需要向我显示一个通知 清单文件Android API上的通知兼容性生成器<;11不工作,android,notifications,android-2.3-gingerbread,Android,Notifications,Android 2.3 Gingerbread,上面的代码在我的Nexus4(安卓4.3)上运行得很好,但我的旧NexusOne(安卓2.3.7)仍然需要向我显示一个通知 清单文件 public static final String NOTIFICATION_TITLE = "Title"; public static final int NOTIFICATION_ID = 1; private NotificationManager mNotificationManager; NotificationCompat.Builder buil
public static final String NOTIFICATION_TITLE = "Title";
public static final int NOTIFICATION_ID = 1;
private NotificationManager mNotificationManager;
NotificationCompat.Builder builder;
private void sendNotification(String msg) {
mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(NOTIFICATION_TITLE)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(msg))
.setAutoCancel(true)
.setContentIntent(contentIntent)
.setContentText(msg);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}
到现在为止我做了什么
- 我知道姜饼需要
,这就是设置pendingent
的原因.setContentIntent
- 我还尝试在
if(Build.VERSION.SDK\u INT<11)
- 即使是旧的(但已弃用的)
也不起作用通知
- 服务器按预期工作,因为4.3设备可以完美地接收通知
所以,现在我已经没有新的想法了,任何人都可以告诉我为什么通知在API 10上不起作用的任何其他选项?我和你有同样的问题,显然我只是注意到只有姜饼版本才起作用 这是一个对我有效的解决方案
您是否尝试过
android.support.v4.app.NotificationCompat.Builder
@MuhammadBabar谢谢,但我已经使用了NotificationCompat.Builder
的support v4库,这就是为什么我无法理解我的问题
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.INTERNET" />
<!-- GCM -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="my.package.matchtracker.permission.C2D_MESSAGE" />
<uses-permission android:name="my.package.permission.C2D_MESSAGE" />
<permission
android:name="my.package.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<application
android:name=".AppClass"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<receiver
android:name=".GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="my.package" />
</intent-filter>
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="my.package" />
</intent-filter>
</receiver>
<service android:name=".GcmIntentService" />
<activity
android:name="my.package.MainActivity"
android:screenOrientation="portrait"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
dependencies {
compile 'com.android.support:support-v4:18.0.+', 'com.google.android.gms:play-services:3.1.+'
}