01.
package
com.jawad.smsapp;
02.
03.
import
android.content.BroadcastReceiver;
04.
import
android.content.Context;
05.
import
android.content.Intent;
06.
import
android.content.pm.PackageManager;
07.
import
android.net.Uri;
08.
import
android.os.Build;
09.
import
android.provider.Telephony;
10.
import
android.support.annotation.RequiresApi;
11.
import
android.telephony.SmsMessage;
12.
import
android.util.Log;
13.
import
android.widget.Toast;
14.
15.
import
com.android.volley.Request;
16.
import
com.android.volley.RequestQueue;
17.
import
com.android.volley.Response;
18.
import
com.android.volley.VolleyError;
19.
import
com.android.volley.toolbox.StringRequest;
20.
import
com.android.volley.toolbox.Volley;
21.
22.
public
class
Sms
extends
BroadcastReceiver{
23.
24.
private
String TAG = Sms.
class
.getSimpleName();
25.
26.
@Override
27.
public
void
onReceive(Context context, Intent intent) {
28.
29.
30.
try
{
31.
Log.d(TAG,
"onReceive: "
);
32.
if
(intent.getAction().equals(
"android.provider.Telephony.SMS_RECEIVED"
)) {
33.
34.
String messag =
new
String();
35.
String sender =
new
String();
36.
37.
38.
SmsMessage[] smsMessages =
new
SmsMessage[
0
];
39.
if
(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
40.
smsMessages = Telephony.Sms.Intents.getMessagesFromIntent(intent);
41.
}
42.
43.
44.
if
(smsMessages ==
null
) {
45.
Toast.makeText(context,
"Smsmessages empty"
, Toast.LENGTH_LONG).show();
46.
return
;
47.
}
48.
for
(SmsMessage message : smsMessages) {
49.
50.
messag = message.getDisplayMessageBody();
51.
sender = message.getDisplayOriginatingAddress();
52.
Log.d(TAG,
"onReceive: "
+ message.getDisplayMessageBody());
53.
Log.d(TAG,
"onReceive: "
+ message.getDisplayOriginatingAddress());
54.
}
55.
56.
58.
59.
60.
Intent intent1 =
new
Intent(Intent.ACTION_VIEW, Uri.parse(url));
61.
62.
Log.d(TAG,
"onReceive: "
+ intent1.resolveActivity(context.getPackageManager()));
63.
if
(intent1.resolveActivity(context.getPackageManager()) !=
null
) {
64.
65.
intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
66.
context.startActivity(intent1);
67.
}
68.
69.
}}
catch
(Exception e)
70.
{
71.
Toast.makeText(context,e.toString(),Toast.LENGTH_LONG).show();
72.
73.
}
74.
}
75.
}