Skip to content
Snippets Groups Projects
Commit 43a9f81d authored by viveksvdy2014's avatar viveksvdy2014
Browse files

Removed Unnecessary Comments !!!

parent 8c9c9f2f
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
<uses-permission android:name="android.permission.SEND_SMS" /> <uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.READ_CONTACTS" /> <uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.RECEIVE_SMS">
<uses-permission android:name="android.permission.READ_SMS" /></uses-permission>
<application <application
android:allowBackup="true" android:allowBackup="true"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
...@@ -21,7 +23,17 @@ ...@@ -21,7 +23,17 @@
<service <service
android:name=".alarmService" android:name=".alarmService"
android:enabled="true" android:enabled="true"
android:exported="true"></service> android:exported="true" />
<receiver android:name="com.speedyapps.keepyousafe.SMSReader$readSMS">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
<service
android:name=".SMSReader"
android:enabled="true"
android:exported="true">
</service>
</application> </application>
</manifest> </manifest>
\ No newline at end of file
package com.speedyapps.keepyousafe; package com.speedyapps.keepyousafe;
import android.content.Intent; import android.content.Intent;
import android.support.annotation.MainThread;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import android.telephony.SmsManager; import android.telephony.SmsManager;
...@@ -15,12 +16,15 @@ public class MainActivity extends AppCompatActivity { ...@@ -15,12 +16,15 @@ public class MainActivity extends AppCompatActivity {
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
intent = new Intent(MainActivity.this,alarmService.class); intent = new Intent(MainActivity.this,alarmService.class);
choice=0; choice=0;
Intent serviceIntent = new Intent(MainActivity.this,SMSReader.class);
startService(serviceIntent);
} }
public void onClick(View view){ public void onClick(View view){
Log.i("zz",""+choice); Log.i("zz",""+choice);
switch(choice) { switch(choice) {
case 0: startService(intent); case 0: startService(intent);
sendSMS("9047570040e","Help Me!!!!"); sendSMS("8606670880","Help Me!!!!");
break; break;
case 1: stopService(intent); case 1: stopService(intent);
break; break;
......
package com.speedyapps.keepyousafe;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.telephony.SmsManager;
import android.telephony.SmsMessage;
import android.util.Log;
import android.widget.Toast;
public class SMSReader extends Service {
public SMSReader() {
}
private static Context myContext;
@Override
public void onCreate() {
Toast.makeText(this, "Created Service", Toast.LENGTH_SHORT).show();
super.onCreate();
myContext = this;
}
@Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not yet implemented");
}
public static class readSMS extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
final SmsManager sms = SmsManager.getDefault();
final Intent alarm = new Intent(myContext,alarmService.class);
// 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();
Log.d("SmsReceiver", "senderNum: "+ senderNum + "; message: " + message);
int count=0;
Handler handler = new Handler();
myContext.startService(alarm);
if(message.equals("Help Me!!!!")){
handler.postDelayed(new Runnable() {
public void run() {
myContext.stopService(alarm);
}
},5000);
}
// Show alert
int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(context, "senderNum "+ senderNum + ", message: " + message, duration);
toast.show();
} // end for loop
} // bundle is null
} catch (Exception e) {
Log.e("SmsReceiver", "Exception smsReceiver" +e);
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment