との通知を作成します。私はこのコードの通知を作成しようとしましたBroadcastReceiver
private void setNotificationAlarm(Context context)
{
Intent intent = new Intent(getApplicationContext() , MyNotification.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1000 , pendingIntent);
Log.d("ME", "Alarm started");
}
public class MyNotification extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
Log.d("ME", "Notification started");
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("My notification")
.setContentText("Hello World!");
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, mBuilder.build());
}
}
そして、ここに私のMainfest宣言:
<receiver
android:name=".MyNotification"
android:enabled="true"
android:exported="false" >
</receiver>
私の問題は今、アラームが生成されていること、であるが、通知を表示されません。 BroadcastReceiverはmainfestファイルで宣言されており、コンパイラエラーやランタイムエラーはありません。
私の2番目の問題は、setLatestEventInfo
とnew Notification
コントラクトは廃止されました。私はそれの代わりに何を使うことができますか?あなたが使用することができます
大丈夫感謝のためにそのアクション名を使用して、それをキャッチすることができますが、マニフェスト
に定義されているアクションですそれ。上記のコードを更新しました。今は何も起こりません... – Cilenco
BroadcastReceiversは一般的に何らかのアクションを行います。あなたの放送受信機が動作するアクションを定義し、そのアクションをマニフェスト&インテントに追加します。詳細はこちら[こちら](http://www.vogella.com/articles/AndroidBroadcastReceiver/article.html) –