I am trying to make an application, so that my mobile wakes up when it
receives a sms... I tried and make the app....Here is the code::
package com.atiffarrukh.wakemeup;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.widget.Toast;
public class SmsReceiver extends BroadcastReceiver
{
boolean received = false;
@Override
public void onReceive(Context context, Intent intent)
{
//---get the SMS message passed in---
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String str = "";
if (bundle != null)
{
//---retrieve the SMS message received---
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]);
str += "SMS from " + msgs[i].getOriginatingAddress();
str += " :";
str += msgs[i].getMessageBody().toString();
str += "\n";
received = true;
}
//---display the new SMS message---
Toast.makeText(context, str, Toast.LENGTH_SHORT).show();
Intent i = new Intent(context,WakeUp.class); //for starting
activity from broadcast
i.putExtra("ReceivedCheck", received);//put value of received
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);//flags the intent to
start activity
context.startActivity(i);
}
}
}
and the activity is::
package com.atiffarrukh.wakemeup;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.PowerManager;
public class WakeUp extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
Intent intent = getIntent();
boolean check = intent.getBooleanExtra("ReceivedCheck", false);
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
//Toast.makeText(getBaseContext(), "This is WAKEUP Act",
Toast.LENGTH_SHORT).show();
boolean isScreenOn = pm.isScreenOn();
if(check && !isScreenOn ){
/*getWindow().setFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON,
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
Toast.makeText(getBaseContext(), "This is WAKEUP SCREEN",
Toast.LENGTH_SHORT).show();
*/
//Toast.makeText(getBaseContext(), "This is WAKEUP SCREEN",
Toast.LENGTH_SHORT).show();
final PowerManager.WakeLock wl =
pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My tag");
wl.acquire();
Thread timer = new Thread(){
public void run(){
try {
sleep(5000);
} catch (InterruptedException e) {
// TODO: handle exception
}finally{
wl.release();
}
}
};
timer.start();
}
}
}
ok... What this app do::
1. Wakes up my mobile but few seconds before the message tone...
2. Open a blank black screen with "WakeMeUp" as title...
Now What I want::
1. Wakes up the mobile but almost at same time with the message tone...
2. I dont want that blank screen to open when the activity is called...
If anybody wondering , YES I am new to android and also to programming...
Thanks alot for your help.. in advance... :p
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en