-1
알림이 있는지 알고 나서 조치를 취하는 안드로이드 서비스를 개발하려고합니다. 알림을 관리하는 방법을 모르겠습니다.
알림 작동 방식 및 알림 수신 방법을 알고 싶습니다.서비스 별 알림을 처리하는 방법은 무엇입니까?
알림이 있는지 알고 나서 조치를 취하는 안드로이드 서비스를 개발하려고합니다. 알림을 관리하는 방법을 모르겠습니다.
알림 작동 방식 및 알림 수신 방법을 알고 싶습니다.서비스 별 알림을 처리하는 방법은 무엇입니까?
this answer에서 언급했듯이 BroadcastReceiver를 사용하여 적절한 의도를 파악하고 의도 한 작업을 수행해야합니다.
예를 들어 SMS 메시지를 수신하면 LED가 켜져 야합니다.
// SMS Receiver
<receiver android:name="com.myexample.receivers.SMSReceiver" >
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
... 그래서 같이 약간의 코드를 정의 : here을 언급 한 바와 같이, 당신은 다음처럼 'SMSReceiver'브로드 캐스트 리시버를 등록해야
public class SMSReceiver extends BroadcastReceiver {
private final String DEBUG_TAG = getClass().getSimpleName().toString();
private static final String ACTION_SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
private Context mContext;
private Intent mIntent;
// Retrieve SMS
public void onReceive(Context context, Intent intent) {
mContext = context;
mIntent = intent;
String action = intent.getAction();
if(action.equals(ACTION_SMS_RECEIVED)){
String address, str = "";
int contactId = -1;
SmsMessage[] msgs = getMessagesFromIntent(mIntent);
// Iterate over the received messages with a loop,
// performing the desired actions during the process
}
}
public static SmsMessage[] getMessagesFromIntent(Intent intent) {
Object[] messages = (Object[]) intent.getSerializableExtra("pdus");
byte[][] pduObjs = new byte[messages.length][];
for (int i = 0; i < messages.length; i++) {
pduObjs[i] = (byte[]) messages[i];
}
byte[][] pdus = new byte[pduObjs.length][];
int pduCount = pdus.length;
SmsMessage[] msgs = new SmsMessage[pduCount];
for (int i = 0; i < pduCount; i++) {
pdus[i] = pduObjs[i];
msgs[i] = SmsMessage.createFromPdu(pdus[i]);
}
return msgs;
}
을}
을 ...에 관해서는 LED 문제, 대부분의 보고서는 스케치 같지만,
android.provider.Settings.System.putInt(context.getContentResolver(),
"notification_light_pulse", on ? 1 : 0);
무엇이 있습니까? "알림 듣기"란 뜻입니까? 서비스에서 어떻게 든 알림을 읽고 그에 따라 행동하기를 원한다는 뜻입니까? – ravemir
또한 어떤 알림을 처리할지 알고 있습니까? 어쩌면 당신의 요구에 더 잘 맞을 수있는 BroadcastReceivers를 사용하는 방법이 있을지 모르지만, 그렇지 않다면 귀찮은 접근성 서비스를 사용해야하고 사용자에게 사용 권한을 요청해야합니다. – ravemir
Alread 읽기 또는 어떤 종류의 알림을 원하십니까? https://developer.android.com/guide/topics/ui/notifiers/notifications.html – luxer