코드가 있으며 작동하지 않으므로 다른 사람에게 도움을 요청합니다. 이 특정 문제에 대한 정보는 거의 없습니다.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,
. 나는 그것을 그대로 실행하려고하고 그게 아무것도 보여주지 않습니다. 에뮬레이터에서 실행 중이므로 실제로 중요합니다.
편집 : 작동하지 않는다고 말하면 아무 것도 팝업되지 않습니다. 그것은 잘 실행되지만 알림 결코 나타나지 않습니다.
문제는 :
그래서 문제는 안드로이드 그냥 내 알림을 무시 좁혀된다. 문제는 그것이 왜 나에게 말하지 않는가? -_- 그래서 나는 그것을 고칠 수 없다. 이 문제에 대한 전문가는 내 코드에 문제가있어 알림을 요청합니다. 그것은 에뮬레이터에서 중요합니까?
, 어떻게 내 매니페스트 파일의''태그를 변경해야합니까? –
Andy
실제로 android manifest에서'intent.setAction (..)'을 code + remove''섹션에서 제거 할 수 있습니다. –
방금 했어요. 아직도 작동하지 않습니다. 그래도 그것을 지적 주셔서 감사합니다. 그것의 시작. – Andy