알림이 표시 될 때 알림 표시 줄에 알림을 표시하려고합니다. 아래는 제 코드입니다. 내 최소 API이기 때문에 내가 getNotification()
대신 build()
로 사용하고 여기에Android : 알림 표시 줄에 알림이 표시되지 않습니다.
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.SmsManager;
import android.util.Log;
import android.widget.Toast;
/**
* Created by Yohan on 6/29/2016.
*/
public class AlarmReciever extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
// TODO Auto-generated method stub
// here you can start an activity or service depending on your need
// for ex you can start an activity to vibrate phone or to ring the phone
String message="Hi I will be there later, See You soon";// message to send
// Show the toast like in above screen shot
Log.d("Alarm",message);
Toast.makeText(context, "Alarm Triggered and SMS Sent", Toast.LENGTH_LONG).show();
Intent intent2 = new Intent(context, NotificationReceiverActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(context, (int) System.currentTimeMillis(), intent2, 0);
Notification noti = new Notification.Builder(context)
.setContentTitle("New mail from " + "[email protected]")
.setContentIntent(pIntent).getNotification();
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
// hide the notification after its selected
noti.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, noti);
}
}
AlarmReciever.java은 15
NotificationReceiverActivity.java
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
public class NotificationReceiverActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_notification_receiver);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
}
매니페스트에
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="voice1.xxx.com.alarmcheck2" >
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".BootCompletedReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<receiver
android:name=".AlarmReciever"
android:process=":remote" />
<activity
android:name=".NotificationReceiverActivity"
android:label="@string/title_activity_notification_receiver"
android:theme="@style/AppTheme.NoActionBar" >
</activity>
</application>
</manifest>
내 AlarmReciever.java
Toast
그렇게 해고되어 내가이 작동 알고있다. 그러나 통지는 그렇지 않습니다. 왜 그런지 알아?
알림의 작은 아이콘을 잊어 버린 것 같습니다. https://developer.android.com/guide/topics/ui/notifiers/notifications.html "필수 알림 내용" – Nanis
@Nanis : 감사합니다! 동의 할 수 있도록 의견을 제공해주세요. –