通知不起作用

时间:2014-12-30 11:46:20

标签: android notifications

所以我的通知有问题。它不虎。所以,如果有人可以帮我这个。

这是MainActivity:

Intent myIntent = new Intent(this , NotifyService.class);
    AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
    PendingIntent pendingIntent = PendingIntent.getService(this, 0, myIntent, 0);

    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.HOUR, 0);
    calendar.set(Calendar.AM_PM, Calendar.AM);
    calendar.add(Calendar.DAY_OF_MONTH, 1);

    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 1000*60*60*24 , pendingIntent);

服务类

public class NotifyService extends Service {
@Override
public void onCreate() {
    NotificationCompat.Builder builder =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.ic_launcher)
                    .setContentTitle("Notifications Example")
                    .setContentText("This is a test notification");

    Intent notificationIntent = new Intent(this, MainActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(contentIntent);

    // Add as notification
    NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    manager.notify(FM_NOTIFICATION_ID, builder.build());
}

@Override
public IBinder onBind(Intent intent) {
    return null;
}

}

我的清单

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.berilo.dayabs" >

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/title_activity_main"
        android:launchMode="singleTop">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".ChalangesMenu"
        android:label="@string/title_activity_chalanges_menu" >
    </activity>
    <activity
        android:name=".Workout"
        android:label="@string/title_activity_workout" >
    </activity>
</application>

min Sdk Version是14

所以我将AlarmManager设置为在午夜触发。我在手机上设置时间但没有任何反应。

1 个答案:

答案 0 :(得分:1)

您的NotifyService未在清单文件中声明。

声明它就像

    <service android:name=".NotifyService">
    </service>