5

코드가 있으며 작동하지 않으므로 다른 사람에게 도움을 요청합니다. 이 특정 문제에 대한 정보는 거의 없습니다.Android가 알림 생성을 무시하는 이유는 무엇입니까?

MainActivity


public class MainActivity extends Activity { 
public final int PENDING_INTENT_ID = 8; 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    Button clickity = (Button)findViewById(R.id.alarm_button); 
    clickity.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      Calendar now = Calendar.getInstance(); 
      now.add(Calendar.SECOND, 20); 

      //Create a new PendingIntent used by the Alarm when it activates 
      Intent intent = new Intent(v.getContext(), AlarmReciever.class); 
      intent.setAction("SOME_AWESOME_TRIGGER_WORD"); 
      intent.putExtra("info", "This String shows that the info is actually sent correctly"); 
      PendingIntent pendingIntent = PendingIntent.getBroadcast(v.getContext(), PENDING_INTENT_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT|Intent.FILL_IN_DATA); 

      //Then Create the alarm manager to send this pending intent and set the date to go off 
      AlarmManager am = (AlarmManager)getSystemService(Activity.ALARM_SERVICE); 
      am.set(AlarmManager.RTC_WAKEUP, now.getTimeInMillis(), pendingIntent); 

     } 
    }); 

} 

AlarmReciever


public class AlarmReciever extends BroadcastReceiver{ 

@Override 
public void onReceive(Context c, Intent arg1) { 

    //get a reference to NotificationManager 
    String ns = Context.NOTIFICATION_SERVICE; 
    NotificationManager mNotificationManager = (NotificationManager) c.getSystemService(ns); 

    //Instantiate the notification 

    CharSequence tickerText = "Hello"; 
    long when = System.currentTimeMillis(); 
    Notification.Builder builder = new Notification.Builder(c) 
           .setTicker(tickerText) 
           .setWhen(when) 
           .setContentTitle(arg1.getStringExtra("info")) 
           .setContentText("Success!!") 
           .setAutoCancel(true); 
    Notification notification = builder.getNotification(); 
    mNotificationManager.notify(0, notification);//note the first argument, the ID should be unique 



} 
} 
(나는 그것이 잘못된 철자하지만 그게 전부 때문에 그것이 얼마나, 메신저 그것으로가는 인식) 모든 것을해야한다
<uses-sdk 
    android:minSdkVersion="14" 
    android:targetSdkVersion="15" /> 

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

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 

    <receiver 
     android:name="com.testproject.AlarmReciever" 
     android:enabled="true" 
     android:exported="false" > 
     <intent-filter> 
    </receiver> 

</application> 


매니페스트


16,

. 나는 그것을 그대로 실행하려고하고 그게 아무것도 보여주지 않습니다. 에뮬레이터에서 실행 중이므로 실제로 중요합니다.

편집 : 작동하지 않는다고 말하면 아무 것도 팝업되지 않습니다. 그것은 잘 실행되지만 알림 결코 나타나지 않습니다.

문제는 : enter image description here

그래서 문제는 안드로이드 그냥 내 알림을 무시 좁혀된다. 문제는 그것이 왜 나에게 말하지 않는가? -_- 그래서 나는 그것을 고칠 수 없다. 이 문제에 대한 전문가는 내 코드에 문제가있어 알림을 요청합니다. 그것은 에뮬레이터에서 중요합니까?

답변

2
Intent intent = new Intent(v.getContext(), AlarmReciever.class); 
// intent.setAction("SOME_AWESOME_TRIGGER_WORD"); replace to: 
intent.setAction("com.testproject.SOME_AWESOME_TRIGGER_WORD"); 

적어도 첫번째보기위한

UPD 그것의 :

long firstTime = SystemClock.elapsedRealtime(); 

AlarmManager alarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); 
alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, /* INTERVAL IN MS */ 20 * 1000, /* PendingIntent */ intent); 
+0

, 어떻게 내 매니페스트 파일의''태그를 변경해야합니까? – Andy

+0

실제로 android manifest에서'intent.setAction (..)'을 code + remove''섹션에서 제거 할 수 있습니다. –

+0

방금 ​​했어요. 아직도 작동하지 않습니다. 그래도 그것을 지적 주셔서 감사합니다. 그것의 시작. – Andy

8

음, 교훈은 공지 사항에 배웠습니다. 내가 오류를 얻는 이유는 img를 추가해야하기 때문입니다. 그렇지 않으면 표시되지 않습니다! 내가 가진 모든 것은 기본적으로 블라디미르가 은혜롭게 지적한 바를 제외하고는 옳았습니다. 여기에 다른 사용자를 초대하면 알림을 테스트하는 것과 비슷한 문제가 발생합니다.

22

같은 문제가 발생했습니다. "새 알림()"을 만들 때 아이콘을 지정하지 않으면 알림이 나타나지 않습니다.

+1

하하, 예. 문서에 언급 된 내용을 알려주십시오. 하지만 이봐, 시행 착오 야. 이제 다른 사람들이 알고 있습니다 :) – Andy

0

알림 아이콘을 설정하지 않았기 때문입니다. 알림 아이콘을 설정하면 제대로 작동합니다. 로그 자체는 이미지없이 알림을 보낼 수 없다고 말합니다. 당신이 아이콘을 설정하는 것을 잊었다처럼

0

당신은이어야이 시도 기본 아이콘 ..

를 설정해야합니다 .. 보인다 ..나는 그것을 빼앗아 경우

Notification.Builder builder = new Notification.Builder(c) 
         .setTicker(tickerText) 
         .setWhen(when) 
         .setContentTitle(arg1.getStringExtra("info")) 
         .setContentText("Success!!") 
         .setAutoCancel(true) 
         .setSmallIcon(R.drawable.ic_launcher); //<--- this one 
관련 문제