package com.example.khatrimann.notification;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);
NotificationCompat.Builder b = new NotificationCompat.Builder(this);
b.setTicker("khatrimann")
.setContentTitle("Default notification")
.setContentText("Hey There.")
.setContentIntent(contentIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(1, b.build());
}
}
이 코드는 marshmallow에서 테스트되었으며 충돌하고 작동하지 않습니다.알림 활동이 중단됨
android.support.v4 및 V7은, 모두는 하나 응용 프로그램이 충돌 하나를 시도하고 있습니다. 다음과 같이
로그 캣은 다음과 같습니다
11-20 18:24:59.623 4146-4146/com.example.khatrimann.notification E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.khatrimann.notification, PID: 4146
Theme: themes:{default=overlay:system, iconPack:system, fontPkg:system, com.android.systemui=overlay:system, com.android.systemui.navbar=overlay:system}
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.khatrimann.notification/com.example.khatrimann.notification.MainActivity}: java.lang.IllegalArgumentException: Invalid notification (no valid small icon): Notification(pri=0 contentView=com.example.khatrimann.notification/0x1090085 vibrate=null sound=null tick defaults=0x0 flags=0x0 color=0x00000000 vis=PRIVATE)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2450)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2510)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1363)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5461)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.IllegalArgumentException: Invalid notification (no valid small icon): Notification(pri=0 contentView=com.example.khatrimann.notification/0x1090085 vibrate=null sound=null tick defaults=0x0 flags=0x0 color=0x00000000 vis=PRIVATE)
at android.app.NotificationManager.notify(NotificationManager.java:223)
at android.app.NotificationManager.notify(NotificationManager.java:195)
at com.example.khatrimann.notification.MainActivity.onCreate(MainActivity.java:32)
at android.app.Activity.performCreate(Activity.java:6251)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2403)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2510)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1363)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5461)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
오류는 당신이이 코드 예제처럼, 작은 아이콘을 추가해야합니다 통지를 작성할 때 주요
여기에 로그 캣을 게시 할 수 있습니다. –