read otp from SMS and set to edit text Not working - android

In my application, I am trying to read otp from SMS without typing inside my app.
but it is not working I cant find out the error I am trying to correct the error more than a week please help me to find out where is the mistake, i create a class for reading incoming message and pass the value to my OTPActivity page but null value reaching there
IncomingSms.java
public class IncomingSms extends BroadcastReceiver {
// Get the object of SmsManager
final SmsManager sms = SmsManager.getDefault();
public void onReceive(Context context, Intent intent) {
// Retrieves a map of extended data from the intent.
final Bundle bundle = intent.getExtras();
try {
if (bundle != null) {
final Object[] pdusObj = (Object[]) bundle.get("pdus");
for (int i = 0; i < pdusObj.length; i++) {
SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[i]);
String phoneNumber = currentMessage.getDisplayOriginatingAddress();
String senderNum = phoneNumber;
String message = currentMessage.getDisplayMessageBody().replaceAll("\\D", "");
//message = message.substring(0, message.length()-1);
Log.i("SmsReceiver", "senderNum: " + senderNum + "; message: " + message);
Intent myIntent = new Intent("otp");
myIntent.putExtra("message", message);
myIntent.putExtra("number", senderNum);
LocalBroadcastManager.getInstance(context).sendBroadcast(myIntent);
// Show Alert
}
} // bundle is null
} catch (Exception e) {
Log.e("SmsReceiver", "Exception smsReceiver" + e);
}
}
}
OTPActivity
#Override
public void onResume() {
LocalBroadcastManager.getInstance(this).registerReceiver(receiver, new IntentFilter("otp"));
super.onResume();
}
#Override
public void onPause() {
super.onPause();
LocalBroadcastManager.getInstance(this).unregisterReceiver(receiver);
}
private BroadcastReceiver receiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equalsIgnoreCase("otp")) {
final String message = intent.getStringExtra("message");
// message is the fetching OTP
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
mPinEditText.setText(message);
}
}
};
//Initialization Varibles
private void initViews() {
if ((ActivityCompat.checkSelfPermission(OTPActivity.this, Manifest.permission.READ_SMS) != PackageManager.PERMISSION_GRANTED)) {
ActivityCompat.requestPermissions(OTPActivity.this, new String[]{Manifest.permission.READ_SMS}, 100);
} else {
//Permission Granted
}
}
#Override
public void onRequestPermissionsResult(int requestCode, #NonNull String[] permissions, #NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case 100:
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
//Permission Granted
} else {
//Permission Not Granted
Toast.makeText(getApplicationContext(), "Permission not granted", Toast.LENGTH_SHORT).show();
}
}
}
manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mypkg.appanme">
<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<receiver android:name=".IncomingSms">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
Log shows this error
Permission Denial: receiving Intent { act=android.provider.Telephony.SMS_RECEIVED flg=0x19000010 (has extras) } to com.gameloft.android.HEP.GloftM5HP/.iab.SmsReceiver requires android.permission.RECEIVE_SMS due to sender com.android.phone (uid 1001)

You need to add android:permission="android.permission.BROADCAST_SMS" to your receiver block in AndroidManifest.xml which is required to receive the SMS. Something like this:
<receiver
android:name=".IncomingSms"
android:permission="android.permission.BROADCAST_SMS">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>

If you don't want to write a receiver, you can use a simple lightweight library https://github.com/VitaliBov/SmsInterceptor
You only need to override the interface method, create an Interceptor class and bind it with the life cycle. It looks like this:
public class AuthActivity extends AppCompatActivity implements OnMessageListener {
private SmsInterceptor smsInterceptor;
private EditText etAuthPassword;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_auth);
initViews();
initSmsInterceptor();
}
#Override
protected void onResume() {
super.onResume();
smsInterceptor.register();
}
#Override
protected void onPause() {
super.onPause();
smsInterceptor.unregister();
}
#Override
public void onRequestPermissionsResult(int requestCode, #NonNull String[] permissions, #NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
smsInterceptor.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
#Override
public void messageReceived(String message) {
// You can perform your validation here
etAuthPassword.setText(message);
}
private void initViews() {
etAuthPassword = findViewById(R.id.etAuthPassword);
etAuthPassword.addTextChangedListener(new SmsTextWatcher() {
#Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
if (charSequence.length() == 4) {
btnAuthPassword.setEnabled(true);
checkCode();
} else {
btnAuthPassword.setEnabled(false);
}
}
});
}
private void initSmsInterceptor() {
smsInterceptor = new SmsInterceptor(this, this);
// Not necessary
smsInterceptor.setRegex(SMS_CODE_REGEX);
smsInterceptor.setPhoneNumber(PHONE_NUMBER);
}
private void checkCode() {
// Validation
if (isValid) {
navigateToMainScreen();
}
}
}

Related

API 28: BroadcastReceiver onReceive never executing

My onReceive is never executed. I've tried following guides online including from the official site. I'm testing on a virtual API 28 device. I understand that some of the GUI-related code might be wrong, but I should at least get a log output right? What am I missing?
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.receivesms">
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name=".SMSReceiver"
android:enabled="true"
android:exported="true"
android:permission="android.permission.BROADCAST_SMS">
<intent-filter android:priority="100">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
</application>
Receiver, the first Log.D doesn't even execute:
public class SMSReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Log.d("MESS", intent.getAction());
Bundle bundle = intent.getExtras();
if (bundle != null) {
SmsMessage[] msgs;
String message;
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for (int i=0; i<msgs.length;i++) {
msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i], bundle.getString("format"));
message = msgs[i].getMessageBody();
Log.d("MESS", message);
((EditText) LayoutInflater.from(context).inflate(R.layout.activity_main, null)
.findViewById(R.id.editText)).append(msgs[i].getDisplayOriginatingAddress()
+ "\n" + message + "\n");
}
abortBroadcast();
}
}
}
Main:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
requestSmsPermission();
}
private void requestSmsPermission() {
String permission = Manifest.permission.READ_SMS;
int grant = ContextCompat.checkSelfPermission(this, permission);
if (grant != PackageManager.PERMISSION_GRANTED) {
String[] permission_list = new String[1];
permission_list[0] = permission;
ActivityCompat.requestPermissions(this, permission_list, 1);
} else {
Toast.makeText(this, "Permission granted", Toast.LENGTH_SHORT).show();
Log.d("", "Permission granted");
}
}
#Override
public void onRequestPermissionsResult(int requestCode, #NonNull String[] permissions,
#NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == 1) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
requestSmsPermission();
} else {
Toast.makeText(this, "permission not granted", Toast.LENGTH_SHORT).show();
}
}
}
}
Your actual problem is in the SMS PERMISSION. You only request READ_SMS Permission from user not RECEIVE_SMS permission. You also have to give this permission to achieve this.
Manifest.permission.RECEIVE_SMS
Try adding this:
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_SMS, Manifest.permission.RECEIVE_SMS}, 1);
It looks like:
private void requestSmsPermission() {
String readSms = Manifest.permission.READ_SMS;
String receiveSms = Manifest.permission.RECEIVE_SMS;
int grant = ContextCompat.checkSelfPermission(this, readSms) + ContextCompat.checkSelfPermission(this, receiveSms);
if (grant != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{readSms, receiveSms}, 1);
} else {
Toast.makeText(this, "Permission granted", Toast.LENGTH_SHORT).show();
Log.d("", "Permission granted");
}
}
try to increase the priority so that your app receives the SMS first, I would set it to max:
<intent-filter android:priority="2147483647">

Unable to receive SMS in Android Marshmallow

I´m unable to toast SMS in Android Marshmallow.
Manifest File:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.asim.smsreceive">
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<activity android:name="com.example.asim.smsreceive.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- BroadcastReceiver that listens for incoming SMS messages -->
<receiver
android:name=".SmsReceiver"
android:enabled="true"
android:exported="true" >
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
</intent-filter>
</receiver>
</application>
</manifest>
This is Broadcast Receiver Code unable to receive SMS:
package com.example.asim.smsreceive;
public class SmsReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if(intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")){
Bundle bundle = intent.getExtras(); //---get the SMS message passed in---
SmsMessage[] msgs = null;
String msg_from;
if (bundle != null){
//---retrieve the SMS message received---
try{
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for(int i=0; i<msgs.length; i++){
msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
msg_from = msgs[i].getOriginatingAddress();
String msgBody = msgs[i].getMessageBody();
Toast.makeText(context,msgBody,Toast.LENGTH_LONG).show();
}
}catch(Exception e){
// Log.d("Exception caught",e.getMessage());
}
}
}
}
}
Main Activity
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
protected void onStart() {
super.onStart();
// Here, thisActivity is the current activity
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.RECEIVE_SMS)
!= PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.RECEIVE_SMS},
1);
// MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
// app-defined int constant. The callback method gets the
// result of the request.
}
}
}
You have ask for the permission at run time:
if (ContextCompat.checkSelfPermission(thisActivity,Manifest.permission.READ_EXTERNAL_STORAGE)!= PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
Manifest.permission.READ_EXTERNAL_STORAGE)) {
// Show an explanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(thisActivity,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
REQUEST_PERMISSION);
// MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
// app-defined int constant. The callback method gets the
// result of the request.
}
}
and than do what ever you want (if the user grants the permission):
#Override
public void onRequestPermissionsResult(final int requestCode, #NonNull final String[] permissions, #NonNull final int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == REQUEST_PERMISSION) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// Permission granted.
} else {
// User refused to grant permission.
}
}
}
You can read more here: https://developer.android.com/training/permissions/requesting.html

How to receive sms in android API 25 (Nougat)

I have been using these code to receive sms in actual device android 4.2 and it was working fine, Now I came to know about new permission module so this code in android 7 nougat not working for me.
public class sms extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
if (bundle != null) {
Object[] smsExtra = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[smsExtra.length];
for (int i = 0; i < msgs.length; i++) {
SmsMessage sms = SmsMessage.createFromPdu((byte[]) smsExtra[i]);
String body = sms.getMessageBody().toString();
String sender = sms.getOriginatingAddress().toString();
Toast.makeText(context, "From :"+sender+"\n"+"body:"+body, Toast.LENGTH_LONG).show();
}
}
}
}
I found this about marshmallow that there is run time permission required, But i don't get it how and where to add it in my code so that it work in Nougat and below apis.
// in manifest.xml
<uses-permission android:name="android.permission.RECEIVE_SMS" />
try this to read sms permisson runtime
requestSmsPermission();
private void requestSmsPermission() {
String permission = Manifest.permission.READ_SMS;
int grant = ContextCompat.checkSelfPermission(this, permission);
if (grant != PackageManager.PERMISSION_GRANTED) {
String[] permission_list = new String[1];
permission_list[0] = permission;
ActivityCompat.requestPermissions(this, permission_list, 1);
}
}
#Override
public void onRequestPermissionsResult(int requestCode, #NonNull String[] permissions,
#NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == 1) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Toast.makeText(AccountClass.this,"permission granted", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(AccountClass.this,"permission not granted", Toast.LENGTH_SHORT).show();
}
}
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.messagebox);
if (!CheckPermission(MessageBox.this, Manifest.permission.READ_SMS)) {
RequestPermission(MessageBox.this, Manifest.permission.READ_SMS, REQUEST_RUNTIME_PERMISSION);
}
}
#Override
public void onRequestPermissionsResult(int permsRequestCode, String[] permissions, int[] grantResults) {
switch (permsRequestCode) {
case REQUEST_RUNTIME_PERMISSION: {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// you have permission go ahead
//createApplicationFolder();
} else {
// you do not have permission show toast.
}
return;
}
}
}
public void RequestPermission(Activity thisActivity, String Permission, int Code) {
if (ContextCompat.checkSelfPermission(thisActivity, Permission) != PackageManager.PERMISSION_GRANTED)
{
if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity, Permission))
{ }
else
{
ActivityCompat.requestPermissions(thisActivity, new String[]{Permission}, Code);
}
}
}
public boolean CheckPermission(Context context, String Permission) {
if (ContextCompat.checkSelfPermission(context, Permission) == PackageManager.PERMISSION_GRANTED) {
return true;
} else {
return false;
}
}

onRequestPermissionsResult is not called back in an android activity

I am trying to get the camera permission from the user before launching my camera activity. onRequestPermissionsResult is never called back after the user presses "Allow" from the permission dialog. Here is my Activity class:
public class ImageCaptureActivity extends AppCompatActivity {
public static final String TAG = ImageCaptureActivity.class.getSimpleName();
private static final int REQUEST_CAMERA = 0;
private static final int REQUEST_CAMERA_PERMISSION = 1;
private Point mSize;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_image_capture);
Display display = getWindowManager().getDefaultDisplay();
mSize = new Point();
display.getSize(mSize);
// Request for Camera Permission
requestForCameraPermission(findViewById(android.R.id.content));
}
/**
* #param view
* #brief requestForCameraPermission
*/
public void requestForCameraPermission(View view) {
Log.v(TAG, "Requesting Camera Permission");
final String permission = Manifest.permission.CAMERA;
if (ContextCompat.checkSelfPermission(ImageCaptureActivity.this, permission)
!= PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(ImageCaptureActivity.this, permission)) {
showPermissionRationaleDialog(getString(R.string.camera_permission_rationale), permission);
} else {
requestForPermission(permission);
}
} else {
launch();
}
}
/**
* #param message
* #param permission
* #brief showPermissionRationaleDialog
*/
private void showPermissionRationaleDialog(final String message, final String permission) {
new AlertDialog.Builder(ImageCaptureActivity.this)
.setMessage(message)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
ImageCaptureActivity.this.requestForPermission(permission);
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
}
})
.create()
.show();
}
/**
* #param permission
* #brief requestForPermission
*/
private void requestForPermission(final String permission) {
ActivityCompat.requestPermissions(ImageCaptureActivity.this, new String[]{permission}, REQUEST_CAMERA_PERMISSION);
}
/**
* #brief launch
*/
private void launch() {
Log.v(TAG, "Camera Permission Granted, launching the CameraActivity");
String documentId = getIntent().getStringExtra(IntentNames.INTENT_EXTRA_WIP_DOCUMENT_ID);
Intent startCustomCameraIntent = new Intent(this, CameraActivity.class);
startCustomCameraIntent.putExtra(IntentNames.INTENT_EXTRA_WIP_DOCUMENT_ID, documentId);
startActivityForResult(startCustomCameraIntent, REQUEST_CAMERA);
}
#Override
public void onRequestPermissionsResult(int requestCode, #NonNull String[] permissions, #NonNull int[] grantResults) {
switch (requestCode) {
case REQUEST_CAMERA_PERMISSION:
final int numOfRequest = grantResults.length;
final boolean isGranted = numOfRequest == 1
&& PackageManager.PERMISSION_GRANTED == grantResults[numOfRequest - 1];
Log.v(TAG, "Camera Permission callback on onRequestPermissionsResult");
if (isGranted) {
launch();
}
break;
default:
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
}
Here is my App Manifest with the Camera Permission:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapp.testpackage">
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature
android:name="android.hardware.camera.front"
android:required="true" />
<uses-feature android:name="android.hardware.camera2" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
My Gradle Dependency:
compile 'com.android.support:appcompat-v7:24.0.0'
compile 'com.android.support:design:24.0.0'
compile 'com.android.support:support-v4:24.0.0'
I tried your code myself and everything works just fine. I think that the only thing that can be a problem is the scenario when your activity has these two flags:
android:noHistory="true"
android:excludeFromRecents="true"
Here's a guy that is explains the issue: https://stackoverflow.com/a/35772265/5281581

android permission READ_SMS granted but not working (even using REQUEST_CODE_ASK_PERMISSIONS)

I want to create an app that reads all inbox sms and when i tap on a message from the list it sends the data to another activity which contains another list to forward the message to.
the reading SMS worked perfectly before i started working on the other activity.
once i finished the whole app , i ran the application on phone but when there are messages it gives me that android app unfortunately stopped but when i delete all threads it start the app normally with no messages in it. what might be the error ??
here is my main activity and i added the read sms permission in Manifest
public class main extends ListActivity {
final private int REQUEST_CODE_ASK_PERMISSIONS = 123;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT >= 23) {
if (ContextCompat.checkSelfPermission(getBaseContext(), "android.permission.READ_SMS") == PackageManager.PERMISSION_GRANTED){
ActivityCompat.requestPermissions(main.this, new String[]{"android.permission.READ_SMS"}, REQUEST_CODE_ASK_PERMISSIONS);
return;
}
readAllSMS();
} else {
readAllSMS();
}
}
#Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
switch (requestCode) {
case REQUEST_CODE_ASK_PERMISSIONS:
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
readAllSMS();
} else {
Toast.makeText(main.this, "READING SMS Denied", Toast.LENGTH_SHORT)
.show();
}
break;
default:
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
protected void readAllSMS() {
Toast.makeText(main.this, "READING SMS Granted", Toast.LENGTH_SHORT)
.show();
List<SMSData> smsList = new ArrayList<>();
Uri uri = Uri.parse("content://sms/inbox");
Cursor c = getContentResolver().query(uri, null, null, null, null);
startManagingCursor(c);
if (c.moveToFirst()) {
for (int i = 0; i < c.getCount(); i++) {
SMSData sms = new SMSData();
sms.setBody(c.getString(c.getColumnIndexOrThrow("body")).toString());
sms.setNumber(c.getString(c.getColumnIndexOrThrow("address")).toString());
smsList.add(sms);
c.moveToNext();
}
}
c.close();
setListAdapter(new ListAdapter(this, smsList));
}
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
SMSData sms = (SMSData) getListAdapter().getItem(position);
String msg = "number : " + sms.getNumber() + "\nsent : " + sms.getBody();
sendSMS(msg);
Toast.makeText(getApplicationContext(), sms.getBody(), Toast.LENGTH_LONG).show();
}
private void sendSMS(String message) {
Intent i = new Intent(getApplicationContext(), MainActivity.class);
i.putExtra("SMS_Message",message);
startActivity(i);
}
}

Categories

Resources