Created
August 1, 2016 01:43
-
-
Save dekzitfz/6dc19d3afb4ff2b0d83a911bed69b9b4 to your computer and use it in GitHub Desktop.
Detect incoming sms in android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.annotation.TargetApi; | |
import android.content.BroadcastReceiver; | |
import android.content.Context; | |
import android.content.Intent; | |
import android.content.SharedPreferences; | |
import android.os.Build; | |
import android.os.Bundle; | |
import android.provider.Telephony; | |
import android.telephony.SmsMessage; | |
import android.util.Log; | |
import id.dekz.code.wiratronikcenter.act.ActRegMember; | |
/** | |
* Created by DEKZ on 5/26/2016. | |
*/ | |
public class SmsListener extends BroadcastReceiver { | |
String dari; | |
@TargetApi(Build.VERSION_CODES.KITKAT) | |
@Override | |
public void onReceive(Context context, Intent intent) { | |
if (Telephony.Sms.Intents.SMS_RECEIVED_ACTION.equals(intent.getAction())) { | |
for (SmsMessage smsMessage : Telephony.Sms.Intents.getMessagesFromIntent(intent)) { | |
String messageBody = smsMessage.getMessageBody(); | |
dari = smsMessage.getOriginatingAddress(); | |
Log.d("DARI",smsMessage.getOriginatingAddress()); | |
} | |
String temp = "0"+dari.substring(3); | |
Log.d("DARI temp",temp); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment