Alarm Intent not triggered - Java for Android App Development

Hello,
I am developing an app related to alarm service and facing an issue of Intent not being called.
I have registered for event in manifest file:
<receiver android:name="com.example.myfirstapp.EventTriggerManager" >
</receiver>
And have implemented EventTriggerManager class extended from BroadcastReceiver:
public class EventTriggerManager extends BroadcastReceiver
{
@override
public void onReceive(Context context, Intent intent)
{
System.out.println("Alarm raised");
Toast.makeText(context, "Don't panik You have an alarm!!!!.", Toast.LENGTH_LONG).show();
}
}
Adding an alarm from the Activity class:
Intent intent = new Intent(this, EventTriggerManager.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 12345678, intent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, totalTime, pendingIntent);
But alarm is not getting triggered when totalTime is reached in the system.
Note: totalTime is absolute time used.
Pls point my mistake why the expected output is not seen.
Regards,
Sunil

Sunil K said:
Hello,
I am developing an app related to alarm service and facing an issue of Intent not being called.
I have registered for event in manifest file:
<receiver android:name="com.example.myfirstapp.EventTriggerManager" >
</receiver>
And have implemented EventTriggerManager class extended from BroadcastReceiver:
public class EventTriggerManager extends BroadcastReceiver
{
@override
public void onReceive(Context context, Intent intent)
{
System.out.println("Alarm raised");
Toast.makeText(context, "Don't panik You have an alarm!!!!.", Toast.LENGTH_LONG).show();
}
}
Adding an alarm from the Activity class:
Intent intent = new Intent(this, EventTriggerManager.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 12345678, intent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, totalTime, pendingIntent);
But alarm is not getting triggered when totalTime is reached in the system.
Note: totalTime is absolute time used.
Pls point my mistake why the expected output is not seen.
Regards,
Sunil
Click to expand...
Click to collapse
use this one :
Code:
Intent myIntent = new Intent(Current.this , NotifyService.class);
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
pendingIntent = PendingIntent.getService(ThisApp.this, 0, myIntent, 0);
insted of :
Code:
Intent intent = new Intent(this, EventTriggerManager.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 12345678, intent, 0);

mohamedrashad said:
use this one :
Code:
Intent myIntent = new Intent(Current.this , NotifyService.class);
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
pendingIntent = PendingIntent.getService(ThisApp.this, 0, myIntent, 0);
insted of :
Code:
Intent intent = new Intent(this, EventTriggerManager.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 12345678, intent, 0);
Click to expand...
Click to collapse
My EventTriggerManager extends BroadcastReceiver and it is not service right? Correct me if wrong.
I tried with the above changes but facing error:
04-19 21:25:00.019: W/ActivityManager(885): Unable to start service Intent { flg=0x4 cmp=com.example.myfirstapp/.EventTriggerManager (has extras) }: not found

Sunil K said:
My EventTriggerManager extends BroadcastReceiver and it is not service right? Correct me if wrong.
I tried with the above changes but facing error:
04-19 21:25:00.019: W/ActivityManager(885): Unable to start service Intent { flg=0x4 cmp=com.example.myfirstapp/.EventTriggerManager (has extras) }: not found
Click to expand...
Click to collapse
sorry I copied this from an old app I made, change get service => get broadcast and the notify.class to your reciver

mohamedrashad said:
sorry I copied this from an old app I made, change get service => get broadcast and the notify.class to your reciver
Click to expand...
Click to collapse
That is what I had done right:
Intent intent = new Intent(this, EventTriggerManager.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 12345678, intent, 0);
Here eventTriggerManager is my receiver class. But alarm is not recevied by application

Sunil K said:
That is what I had done right:
Intent intent = new Intent(this, EventTriggerManager.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 12345678, intent, 0);
Here eventTriggerManager is my receiver class. But alarm is not recevied by application
Click to expand...
Click to collapse
Try this
PHP:
int time;
PendingIntent pi;
BroadcastReceiver br;
AlarmManager am;
br = new BroadcastReceiver() {
@Override
public void onReceive(Context c, Intent i) {
yourMethod();
//called when alarmmanager triggers pending intent
}
};
registerReceiver(br, new IntentFilter("com.your.packagename"));
pi = PendingIntent.getBroadcast(this, 0, new Intent(
"com.your.packagename"), 0);
am = (AlarmManager) (this.getSystemService(Context.ALARM_SERVICE));
if (you want repeating alarm ?) {
am.setRepeating(AlarmManager.RTC, System.currentTimeMillis(),
1000 * time, pi);
} else {
am.set(AlarmManager.ELAPSED_REALTIME,
SystemClock.elapsedRealtime() + 1000 * time, pi);
}
And please use the CODE tags, next time you want to post some code

gh0stslayer said:
Try this
PHP:
int time;
PendingIntent pi;
BroadcastReceiver br;
AlarmManager am;
br = new BroadcastReceiver() {
@Override
public void onReceive(Context c, Intent i) {
yourMethod();
//called when alarmmanager triggers pending intent
}
};
registerReceiver(br, new IntentFilter("com.your.packagename"));
pi = PendingIntent.getBroadcast(this, 0, new Intent(
"com.your.packagename"), 0);
am = (AlarmManager) (this.getSystemService(Context.ALARM_SERVICE));
if (you want repeating alarm ?) {
am.setRepeating(AlarmManager.RTC, System.currentTimeMillis(),
1000 * time, pi);
} else {
am.set(AlarmManager.ELAPSED_REALTIME,
SystemClock.elapsedRealtime() + 1000 * time, pi);
}
And please use the CODE tags, next time you want to post some code
Click to expand...
Click to collapse
Hello,
Alarms are getting received only when activity is running it is not otherwise.
Googled and tried below flag for intent :
Code:
i.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
Also applied below permissions for app:
Code:
<uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>
<uses-permission android:name="com.android.alarm.permission.SET_ALARM"></uses-permission>
But nothing worked though. Can you please help me finding solution to it?

Sunil K said:
Hello,
Alarms are getting received only when activity is running it is not otherwise.
Googled and tried below flag for intent :
Code:
i.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
Also applied below permissions for app:
Code:
<uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>
<uses-permission android:name="com.android.alarm.permission.SET_ALARM"></uses-permission>
But nothing worked though. Can you please help me finding solution to it?
Click to expand...
Click to collapse
If you want to keep it running in the background you should put that code in a background service. You can get lots of examples on google. Start the service when you want to use it. You can use boot receiver to start the service if you want the alarm intent to start every time the app boots.
Sent from my Galaxy Nexus using Tapatalk

gh0stslayer said:
If you want to keep it running in the background you should put that code in a background service. You can get lots of examples on google. Start the service when you want to use it. You can use boot receiver to start the service if you want the alarm intent to start every time the app boots.
Sent from my Galaxy Nexus using Tapatalk
Click to expand...
Click to collapse
Thank you, I will explore this more

Sunil K said:
Thank you, I will explore this more
Click to expand...
Click to collapse
good luck, post again if you face some problems.
Sent from my Galaxy Nexus using Tapatalk

Related

[Q] How do you make a clock widget open Alarm Clock App?

Okay, so i asked this question a while back and didnt get much help, but I am extremely lost. My partner who before actually programmed the app put in the necessary stuff, however i dont think it works in froyo+. I am extremely new to programming in general, and i cannot for the life of me figure this out. I have even tried other codes, but they dont work. Can someone please give me a detailed description on how to make a clock widget open the alarm clock app.
BTW this is the code that we are using at the moment:
package honeycomb.clocks;
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.widget.RemoteViews;
public class BlueClock extends AppWidgetProvider
{
public void onReceive(Context context, Intent intent)
{
String action = intent.getAction();
if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action))
{
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.blueclock);
Intent ClocksIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER).setComponent(new ComponentName("com.android.alarmclock", "com.android.alarmclock.AlarmClock"));
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, ClocksIntent, 0);
views.setOnClickPendingIntent(R.id.Widget, pendingIntent);
AppWidgetManager.getInstance(context).updateAppWidget(intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS), views);
}
}
}
Click to expand...
Click to collapse
Hi,
I don't know if there's a better aproach, but this is the actual code I'm using to launch the alarm:
Code:
public static final Intent alarmIntent(Context context) {
PackageManager packageManager = context.getPackageManager();
Intent alarmClockIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER);
// Verify clock implementation
String clockImpls[][] = {
{"HTC Alarm ClockDT", "com.htc.android.worldclock", "com.htc.android.worldclock.WorldClockTabControl" },
{"Standar Alarm ClockDT", "com.android.deskclock", "com.android.deskclock.AlarmClock"},
{"Froyo Nexus Alarm ClockDT", "com.google.android.deskclock", "com.android.deskclock.DeskClock"},
{"Moto Blur Alarm ClockDT", "com.motorola.blur.alarmclock", "com.motorola.blur.alarmclock.AlarmClock"},
{"Samsung Galaxy S", "com.sec.android.app.clockpackage","com.sec.android.app.clockpackage.ClockPackage"}
};
boolean foundClockImpl = false;
for(int i=0; i<clockImpls.length; i++) {
String packageName = clockImpls[i][1];
String className = clockImpls[i][2];
try {
ComponentName cn = new ComponentName(packageName, className);
packageManager.getActivityInfo(cn, PackageManager.GET_META_DATA);
alarmClockIntent.setComponent(cn);
foundClockImpl = true;
} catch (NameNotFoundException nf) {
}
}
if (foundClockImpl)
return alarmClockIntent;
else
return null;
}
Hope it helps!
pmduque said:
Hi,
I don't know if there's a better aproach, but this is the actual code I'm using to launch the alarm:
Code:
public static final Intent alarmIntent(Context context) {
PackageManager packageManager = context.getPackageManager();
Intent alarmClockIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER);
// Verify clock implementation
String clockImpls[][] = {
{"HTC Alarm ClockDT", "com.htc.android.worldclock", "com.htc.android.worldclock.WorldClockTabControl" },
{"Standar Alarm ClockDT", "com.android.deskclock", "com.android.deskclock.AlarmClock"},
{"Froyo Nexus Alarm ClockDT", "com.google.android.deskclock", "com.android.deskclock.DeskClock"},
{"Moto Blur Alarm ClockDT", "com.motorola.blur.alarmclock", "com.motorola.blur.alarmclock.AlarmClock"},
{"Samsung Galaxy S", "com.sec.android.app.clockpackage","com.sec.android.app.clockpackage.ClockPackage"}
};
boolean foundClockImpl = false;
for(int i=0; i<clockImpls.length; i++) {
String packageName = clockImpls[i][1];
String className = clockImpls[i][2];
try {
ComponentName cn = new ComponentName(packageName, className);
packageManager.getActivityInfo(cn, PackageManager.GET_META_DATA);
alarmClockIntent.setComponent(cn);
foundClockImpl = true;
} catch (NameNotFoundException nf) {
}
}
if (foundClockImpl)
return alarmClockIntent;
else
return null;
}
Hope it helps!
Click to expand...
Click to collapse
Many thanks for this!!
sndytime said:
Many thanks for this!!
Click to expand...
Click to collapse
Unfortunately it didnt help me , Im not a programmer, and I dont know what Im supposed to do with this code and my partner is pissing me off
in order to launch an external activity from an appwidget you need to set a very specific flag on the intent you broadcast. mine was for launching gmail.
Code:
Intent mailClient = new Intent(Intent.ACTION_VIEW);
mailClient.setClassName("com.google.android.gm", "com.google.android.gm.ConversationListActivity");
[B]mailClient.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);[/B]
PendingIntent onClickPending = PendingIntent.getBroadcast(context, 0, mailClient, 0);
RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.gitc_widget_html);
rv.setOnClickPendingIntent(R.id.full_widget, onClickPending);
//then update Your Appwidgets
//AppWidgetManager manager = AppWidgetManager.getInstance(context);
//manager.updateAppWidget(mAppWidgetId, rv);
and please realize that this was kinda a stub of what to do. i left alot out that was specific to my appwidget but that was needed for this to work. but the premise of creating an intent for what you want to launch then creating a pendingIntent and then attaching it to a view of your appwidget and then updating the remote view of you appwidget by using an AppwidgetManager holds true for any situation.
if you need me to elaborate then we can chat then.
-----
o and you aren't updating your appwidgets properly...
you need to get an array of all appwidgets you have and then call updateAppWidget on each like this (again, with my class names and such)
Code:
AppWidgetManager manager = AppWidgetManager.getInstance(context);
int[] ids = manager.getAppWidgetIds(new ComponentName(context, GITextCloud.class));
for (int id : ids) {
manager.updateAppWidget(id, rv);
//rv is the RemoteViews you created earlier up in the program...
//RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.gitc_widget_html);
}
pmduque said:
Hi,
I don't know if there's a better aproach, but this is the actual code I'm using to launch the alarm:
Code:
public static final Intent alarmIntent(Context context) {
PackageManager packageManager = context.getPackageManager();
Intent alarmClockIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER);
// Verify clock implementation
String clockImpls[][] = {
{"HTC Alarm ClockDT", "com.htc.android.worldclock", "com.htc.android.worldclock.WorldClockTabControl" },
{"Standar Alarm ClockDT", "com.android.deskclock", "com.android.deskclock.AlarmClock"},
{"Froyo Nexus Alarm ClockDT", "com.google.android.deskclock", "com.android.deskclock.DeskClock"},
{"Moto Blur Alarm ClockDT", "com.motorola.blur.alarmclock", "com.motorola.blur.alarmclock.AlarmClock"},
{"Samsung Galaxy S", "com.sec.android.app.clockpackage","com.sec.android.app.clockpackage.ClockPackage"}
};
boolean foundClockImpl = false;
for(int i=0; i<clockImpls.length; i++) {
String packageName = clockImpls[i][1];
String className = clockImpls[i][2];
try {
ComponentName cn = new ComponentName(packageName, className);
packageManager.getActivityInfo(cn, PackageManager.GET_META_DATA);
alarmClockIntent.setComponent(cn);
foundClockImpl = true;
} catch (NameNotFoundException nf) {
}
}
if (foundClockImpl)
return alarmClockIntent;
else
return null;
}
Hope it helps!
Click to expand...
Click to collapse
this isnt actually launching the clock application. you are just returning an intent that can be used to launch the clock application (still need to make a pendingIntent and attach it to a view). there is a difference and a new programmer could be very confused by this post.
other than that it looks like a nice way to find the class and package names for what clock is installed. =)
schwartzman93 said:
Unfortunately it didnt help me , Im not a programmer, and I dont know what Im supposed to do with this code and my partner is pissing me off
Click to expand...
Click to collapse
Code:
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.widget.RemoteViews;
public class Widget2 extends AppWidgetProvider
{
public void onReceive(Context context, Intent intent)
{
String action = intent.getAction();
PendingIntent pendingIntent;
if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action))
{
RemoteViews views = new RemoteViews(context.getPackageName(),
R.layout.widget2);
pendingIntent = PendingIntent.getActivity(context, 0,getAlarmPackage(context), 0);
views.setOnClickPendingIntent(R.id.Widget2, pendingIntent);
AppWidgetManager
.getInstance(context)
.updateAppWidget(
intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS),
views);
}
}
public Intent getAlarmPackage(Context context)
{
PackageManager packageManager = context.getPackageManager();
Intent AlarmClockIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER);
String clockImpls[][] = {
{ "Standard Alarm", "com.android.alarmclock",
"com.android.alarmclock.AlarmClock" },
{ "HTC Alarm ClockDT", "com.htc.android.worldclock",
"com.htc.android.worldclock.WorldClockTabControl" },
{ "Standard Alarm ClockDT", "com.android.deskclock",
"com.android.deskclock.AlarmClock" },
{ "Froyo Nexus Alarm ClockDT",
"com.google.android.deskclock",
"com.android.deskclock.DeskClock" },
{ "Moto Blur Alarm ClockDT",
"com.motorola.blur.alarmclock",
"com.motorola.blur.alarmclock.AlarmClock" },
{ "Samsung Galaxy S", "com.sec.android.app.clockpackage",
"com.sec.android.app.clockpackage.ClockPackage" } };
boolean foundClockImpl = false;
for (int i = 0; i < clockImpls.length; i++)
{
String packageName = clockImpls[i][1];
String className = clockImpls[i][2];
try
{
ComponentName cn = new ComponentName(packageName, className);
packageManager.getActivityInfo(cn,PackageManager.GET_META_DATA);
AlarmClockIntent.setComponent(cn);
foundClockImpl = true;
} catch (NameNotFoundException nf)
{
}
}
if (foundClockImpl)
{
return AlarmClockIntent;
}
else
{
return null;
}
}
}
Here is the Complete Source of my Appwidget Provider it generates a Clickevent on Appwidget to start the specific alarm app on the different phones.
Here is the Link to the simple Clock widget i have extended
Hope this helps!!
SUCCESS!!!!! Thank you guys so much, you have no idea how grateful I am for your help.

[Q] AppWidget Creation Intents

i was struggling with creating an onClickListener for an Appwidget so instead of setting it in onUpdate i was doing it in one of the later intents in onRecieve. are the Intents used to create AppWidgets the same for all android phones? cause they have some pretty dubious names for CM7 on my Inspire 4G? can anyone confirm that these are the same on another build of Android?
I/GITextCloud(32189): android.appwidget.action.APPWIDGET_ENABLED
I/GITextCloud(32189): android.appwidget.action.APPWIDGET_UPDATE
I/GITextCloud(32189): com.motorola.blur.home.ACTION_SET_WIDGET_SIZE
I/GITextCloud(32189): mobi.intuitit.android.hpp.ACTION_READY
are these the same for every build of android? i am using CM7 on an Inspire 4G so why is a motorola blur intent being sent? or an intuitit intent? can i rely on these being there for all builds of android? not just CM7?
---------------------
i rambled in my original post. it was quite insane. it is in the second post.
I have had a rather strange problem with one of my AppWidgets i am writing. i have it so when the widget is clicked gmail opens. the problem arrises from when the setOnClickListener is run.
normally one would recommend setting your onClickListeners in the onUpdate() method as it is the easiest since all the info you need is passed to it. but when it is like this the onClickListener is set before the widget exists on the screen and thus the onClickListener doesnt attach. clicking the widget does nothing.
Code:
/** Called when the activity is first created. */
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
//attach an onClick intent to the layout
final Intent onClick = new Intent(context, GITextCloud.class);
onClick.setAction(LAUNCH_GMAIL_GAPPS);
PendingIntent onClickPending = PendingIntent.getBroadcast(context, 0, onClick, 0);
RemoteViews rv1 = new RemoteViews(context.getPackageName(), R.layout.gitc_widget_html);
rv1.setOnClickPendingIntent(R.id.full_widget, onClickPending);
for (int appWidgetId : appWidgetIds) {
appWidgetManager.updateAppWidget(appWidgetId, rv1);
}
}
so i decided i would perform my setOnClickListener action after returning from WidgetConfig Activity. upon exiting the Config i sent a delayed broadcast to my widget which i would catch in the onRecieve method like so
Code:
@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
// other intent catches....
if (intent.getAction().equals(SETUP_DELAY)) {
Toast.makeText(context, "setup delay over", Toast.LENGTH_LONG).show();
//attach an onClick intent to the layout
final Intent onClick = new Intent(context, GITextCloud.class);
onClick.setAction(LAUNCH_GMAIL_GAPPS);
PendingIntent onClickPending = PendingIntent.getBroadcast(context, 0, onClick, 0);
RemoteViews rv1 = new RemoteViews(context.getPackageName(), R.layout.gitc_widget_html);
rv1.setOnClickPendingIntent(R.id.full_widget, onClickPending);
AppWidgetManager manager = AppWidgetManager.getInstance(context);
int[] ids = manager.getAppWidgetIds(new ComponentName(context, GITextCloud.class));
for (int id : ids) {
manager.updateAppWidget(id, rv1);
}
}
// other intent catches....
}
now that works great as long as you press ok on the AppWidget size confirmation before the time on the delayed broadcast from my Config Activity runs out.
so i decided i would look at what intents the appwidget was receiving and perform the setOnClickListener at the last intent received.
they are as follows...
I/GITextCloud(32189): android.appwidget.action.APPWIDGET_ENABLED
I/GITextCloud(32189): android.appwidget.action.APPWIDGET_UPDATE
I/GITextCloud(32189): com.motorola.blur.home.ACTION_SET_WIDGET_SIZE
I/GITextCloud(32189): mobi.intuitit.android.hpp.ACTION_READY
are these the same for every build of android? i am using CM7 on an Inspire 4G so why is a motorola blur intent being sent? or an intuitit intent? can i rely on these being there for all builds of android? not just CM7?
Click to expand...
Click to collapse
rambling and quite unnecessary
are we devoid of any knowledge of this?

[Help required] AlarmManager running within a service

Hi, So I have managed to get similar code working in the main/ui thread but I was wondering if any of you may know why I cant get this running in my Service code?
I need the Code to run the onStart Segment at the set time...
Thanx In Advance!
Code:
public class Service1 extends Service {
public BroadcastReceiver alarmReceiver;
public PendingIntent pendingIntent;
public AlarmManager alarmManager;
public Handler serviceHandler;
@Override
public void onCreate()
{
alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
int H1 = Integer.parseInt(loadHour());
int M1 = Integer.parseInt(loadMin());
int D1 = Integer.parseInt(loadDay());
if (calendar.get(Calendar.HOUR_OF_DAY) > H1)
{
D1+=1;
}
calendar.set(Calendar.DAY_OF_YEAR, D1);
calendar.set(Calendar.HOUR_OF_DAY, H1);
calendar.set(Calendar.MINUTE, M1);
calendar.set(Calendar.SECOND, 00);
alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
};
public void onStart()
{
Intent intent = new Intent(ALARM_REFRESH_ACTION);
pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
alarmReceiver = new BroadcastReceiver()
{
@Override
public void onReceive(Context context, Intent intent)
{
Toast.makeText(Service1.this, "Success!", Toast.LENGTH_LONG).show();
}
};

[Q] Dialog out of Activity

Hello app developers!
I have got serious problem. Every time I call alertdialogs or other dialogs I see them only in activity. But my app needs to show this dialog when user works on phone, that's why it must be shown out of activity. Any ideas?
DoR2 said:
Hello app developers!
I have got serious problem. Every time I call alertdialogs or other dialogs I see them only in activity. But my app needs to show this dialog when user works on phone, that's why it must be shown out of activity. Any ideas?
Click to expand...
Click to collapse
You cannot do this. There is simply no feature for that. I have had that problem, too.
Use a Notification or a Toast message.
There is a work-around for this. If you run a service, you can technically launch an activity that can resemble this.
I have an app that uses a broadcast receiver to listen for the events I want to alert my user to. I created a custom layout for my alert dialog and then when the event happens, my broadcast receiver calls the activity.
zalez said:
There is a work-around for this. If you run a service, you can technically launch an activity that can resemble this.
I have an app that uses a broadcast receiver to listen for the events I want to alert my user to. I created a custom layout for my alert dialog and then when the event happens, my broadcast receiver calls the activity.
Click to expand...
Click to collapse
Yes, great idea. Launch a transparent Activity and start a dialog. Set an onDismissListener and close the app when the dialog is closed.
nikwen said:
Yes, great idea. Launch a transparent Activity and start a dialog. Set an onDismissListener and close the app when the dialog is closed.
Click to expand...
Click to collapse
If I start a transparent activity user can't see that it was started as I understand. Can you give code for broadcast receiver maybe I misunderstand something
The broadcast receiver is just the mechanism I use to launch the activity. It is a mere intent that I start from it. Below is the class I use for my alertdialog. You won't be able to cut and paste because I also created my own class to dismiss the activity.
Code:
public class SilentDialog extends TimedActivity implements OnTouchListener{
Intent intent;
[user=439709]@override[/user]
public void onCreate(Bundle savedInstanceState) {
//Remove title bar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
//Remove notification bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
showAlert();
}
[user=439709]@override[/user]
protected void onDestroy()
{
//this is very important here ;)
super.onDestroy();
}
public boolean onTouch(View v, MotionEvent event)
{
final int actionPerformed = event.getAction();
//reset idle timer
// put this here so that the touching of empty space is captured too
// it seems that LinearLayout doesn't trigger a MotionEvent.ACTION_UP or MotionEvent.ACTION_MOVE
if (actionPerformed == MotionEvent.ACTION_DOWN)
{
super.onTouch();
}
return false;//do not consume event!
}
public void showAlert(){
//would you like it to expire?
AlertDialog.Builder builder;
final AlertDialog alertDialog;
Context mContext = SilentDialog.this;
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.pop1,
(ViewGroup) findViewById(R.id.layout_root));
NumberPicker spin = (NumberPicker) layout.findViewById(R.id.SpinRate);
spin.setVisibility(8);
TextView rate = (TextView) layout.findViewById(R.id.RateTitle);
rate.setVisibility(8);
TextView text = (TextView) layout.findViewById(R.id.txtAlertDiag);
text.setText("ButlerSMS has detected the ringer mode has changed to silent. " +
"\n\n Would you like ButlerSMS to turn on?");
final NumberPicker picker = (NumberPicker) layout.findViewById(R.id.SpinRate);
picker.setValue(60);
builder = new AlertDialog.Builder(mContext);
builder.setView(layout);
builder.setTitle("ButlerSMS - Silent Mode");
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
intent = new Intent(getBaseContext(), ButlerWidget.class);
intent.setAction("StartSMS");
intent.putExtra("msg","Normal");
sendBroadcast(intent);
finish();
}
});
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Canceled.
finish();
}
});
alertDialog = builder.create();
alertDialog.show();
final Timer t = new Timer();
t.schedule(new TimerTask() {
public void run() {
alertDialog.dismiss(); // when the task is active then close the dialog
t.cancel(); // also just top the timer thread, otherwise, you may receive a crash report
finish();
}
}, 19000);
}
}
zalez said:
The broadcast receiver is just the mechanism I use to launch the activity. It is a mere intent that I start from it. Below is the class I use for my alertdialog. You won't be able to cut and paste because I also created my own class to dismiss the activity.
Code:
public class SilentDialog extends TimedActivity implements OnTouchListener{
Intent intent;
[user=439709]@override[/user]
public void onCreate(Bundle savedInstanceState) {
//Remove title bar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
//Remove notification bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
showAlert();
}
[user=439709]@override[/user]
protected void onDestroy()
{
//this is very important here ;)
super.onDestroy();
}
public boolean onTouch(View v, MotionEvent event)
{
final int actionPerformed = event.getAction();
//reset idle timer
// put this here so that the touching of empty space is captured too
// it seems that LinearLayout doesn't trigger a MotionEvent.ACTION_UP or MotionEvent.ACTION_MOVE
if (actionPerformed == MotionEvent.ACTION_DOWN)
{
super.onTouch();
}
return false;//do not consume event!
}
public void showAlert(){
//would you like it to expire?
AlertDialog.Builder builder;
final AlertDialog alertDialog;
Context mContext = SilentDialog.this;
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.pop1,
(ViewGroup) findViewById(R.id.layout_root));
NumberPicker spin = (NumberPicker) layout.findViewById(R.id.SpinRate);
spin.setVisibility(8);
TextView rate = (TextView) layout.findViewById(R.id.RateTitle);
rate.setVisibility(8);
TextView text = (TextView) layout.findViewById(R.id.txtAlertDiag);
text.setText("ButlerSMS has detected the ringer mode has changed to silent. " +
"\n\n Would you like ButlerSMS to turn on?");
final NumberPicker picker = (NumberPicker) layout.findViewById(R.id.SpinRate);
picker.setValue(60);
builder = new AlertDialog.Builder(mContext);
builder.setView(layout);
builder.setTitle("ButlerSMS - Silent Mode");
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
intent = new Intent(getBaseContext(), ButlerWidget.class);
intent.setAction("StartSMS");
intent.putExtra("msg","Normal");
sendBroadcast(intent);
finish();
}
});
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Canceled.
finish();
}
});
alertDialog = builder.create();
alertDialog.show();
final Timer t = new Timer();
t.schedule(new TimerTask() {
public void run() {
alertDialog.dismiss(); // when the task is active then close the dialog
t.cancel(); // also just top the timer thread, otherwise, you may receive a crash report
finish();
}
}, 19000);
}
}
Click to expand...
Click to collapse
I understood everything except the way how app switch between position before signal came and required activity with alert dialog in it. As I see this code initialize activity and alert dialog but don't contain switching that I need
Are you asking how I call the dialog? If so, a simple intent from a broadcast receiver.
Code:
Intent i = new Intent(context, SilentDialog.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
I would use the AlertDialog.Builder class for compatibility.
Why not use a notification, I think that is more elegant.
Code:
public class InstalledReceiver extends BroadcastReceiver {
private NotificationManager mNotificationManager ;
[user=439709]@override[/user]
public void onReceive(Context context, Intent intent) {
if (BaseActivity.DEBUG) System.out.println("Received Broadcast");
Boolean update = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
mNotificationManager = (NotificationManager) context.getSystemService("notification");
SharedPreferences getPrefs = PreferenceManager.getDefaultSharedPreferences(context);
Boolean disabledNotifications = getPrefs.getBoolean("disableNotifications", false);
if (!disabledNotifications && !update) makeNotification(context);
}
private void makeNotification(Context context) {
CharSequence label = context.getString(R.string.labelNotify);
CharSequence text = context.getString(R.string.textNotify);
CharSequence full = context.getString(R.string.fullNotify);
final Notification notification = new Notification(R.drawable.ic_launcher,text,System.currentTimeMillis());
notification.setLatestEventInfo(context,label,full,null);
notification.defaults = Notification.DEFAULT_ALL;
mNotificationManager.notify( 0, notification);
}
}
Taptalked u see .. əəs n pəʞlɐʇdɐʇ
Zatta said:
Why not use a notification, I think that is more elegant.
Code:
public class InstalledReceiver extends BroadcastReceiver {
private NotificationManager mNotificationManager ;
[user=439709]@override[/user]
public void onReceive(Context context, Intent intent) {
if (BaseActivity.DEBUG) System.out.println("Received Broadcast");
Boolean update = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
mNotificationManager = (NotificationManager) context.getSystemService("notification");
SharedPreferences getPrefs = PreferenceManager.getDefaultSharedPreferences(context);
Boolean disabledNotifications = getPrefs.getBoolean("disableNotifications", false);
if (!disabledNotifications && !update) makeNotification(context);
}
private void makeNotification(Context context) {
CharSequence label = context.getString(R.string.labelNotify);
CharSequence text = context.getString(R.string.textNotify);
CharSequence full = context.getString(R.string.fullNotify);
final Notification notification = new Notification(R.drawable.ic_launcher,text,System.currentTimeMillis());
notification.setLatestEventInfo(context,label,full,null);
notification.defaults = Notification.DEFAULT_ALL;
mNotificationManager.notify( 0, notification);
}
}
Taptalked u see .. əəs n pəʞlɐʇdɐʇ
Click to expand...
Click to collapse
I agree, but if he wants to use a dialog, we help him to make one.
The bad thing about the dialog is that it will interrupt whatever the user is doing. This could be very annoying. And who wants to use an app which has annoying popups?
zalez said:
Are you asking how I call the dialog? If so, a simple intent from a broadcast receiver.
Code:
Intent i = new Intent(context, SilentDialog.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
Click to expand...
Click to collapse
When I use this code activity don't shows when I am out of application. For example Handcent SMS when SMS comes to user shows up a great dialog over all windows. My aim is the same thing
DoR2 said:
When I use this code activity don't shows when I am out of application. For example Handcent SMS when SMS comes to user shows up a great dialog over all windows. My aim is the same thing
Click to expand...
Click to collapse
Start an Activity. Set a transparent layout. Show a dialog. That will result in what you want.
nikwen said:
Start an Activity. Set a transparent layout. Show a dialog. That will result in what you want.
Click to expand...
Click to collapse
I have used this code
Code:
Intent i = new Intent(context, SilentDialog.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
and made transparent layout with dialog, but my dialog appears only in my app
DoR2 said:
I have used this code
Code:
Intent i = new Intent(context, SilentDialog.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
and made transparent layout with dialog, but my dialog appears only in my app
Click to expand...
Click to collapse
Could you please post your code?
nikwen said:
Could you please post your code?
Click to expand...
Click to collapse
How I call activity
Code:
if(answer.contains("BEEP")){
Intent intent=new Intent();
intent.setAction("Navi_Beep");
sendBroadcast(intent);
r.play();
Intent i = new Intent(context, NBeep.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
NBeep.java
Code:
public class NBeep extends Activity {
[user=439709]@override[/user]
public void onCreate(Bundle savedInstanceState) {
Log.d("NaviBeep","Here");
//super.onCreate(savedInstanceState);
super.onCreate(savedInstanceState);
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("Title");
alertDialog.setMessage("Message");
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent intent=new Intent();
intent.setAction("Navi_BeepOff");
sendBroadcast(intent);
finish();
}
});
// Set the Icon for the Dialog
alertDialog.show();
}
}
DoR2 said:
How I call activity
Code:
if(answer.contains("BEEP")){
Intent intent=new Intent();
intent.setAction("Navi_Beep");
sendBroadcast(intent);
r.play();
Intent i = new Intent(context, NBeep.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
NBeep.java
Code:
public class NBeep extends Activity {
[user=439709]@override[/user]
public void onCreate(Bundle savedInstanceState) {
Log.d("NaviBeep","Here");
//super.onCreate(savedInstanceState);
super.onCreate(savedInstanceState);
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("Title");
alertDialog.setMessage("Message");
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent intent=new Intent();
intent.setAction("Navi_BeepOff");
sendBroadcast(intent);
finish();
}
});
// Set the Icon for the Dialog
alertDialog.show();
}
}
Click to expand...
Click to collapse
Ah. You need to call setContentView. Create a transparent View and pass it as a parameter.
nikwen said:
Ah. You need to call setContentView. Create a transparent View and pass it as a parameter.
Click to expand...
Click to collapse
Doesn't help:
Code:
public class NBeep extends Activity {
[user=439709]@override[/user]
public void onCreate(Bundle savedInstanceState) {
Log.d("NaviBeep","Here");
View view=new View(this);
view.setBackgroundColor(Color.TRANSPARENT);
setContentView(view);
super.onCreate(savedInstanceState);
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("Title");
alertDialog.setMessage("Message");
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent intent=new Intent();
intent.setAction("Navi_BeepOff");
sendBroadcast(intent);
finish();
}
});
// Set the Icon for the Dialog
alertDialog.show();
}
}
If you use another layout, is the Activity opened?
Is the "Here" written to the log? Is there any Error message?
And I recommend configuring the AlertDialog within the AlertDialog.Builder: http://www.mkyong.com/android/android-alert-dialog-example/
(However, I guess that it will not solve your problem.)
nikwen said:
If you use another layout, is the Activity opened?
Is the "Here" written to the log? Is there any Error message?
And I recommend configuring the AlertDialog within the AlertDialog.Builder: http://www.mkyong.com/android/android-alert-dialog-example/
(However, I guess that it will not solve your problem.)
Click to expand...
Click to collapse
I finally made it!:victory: Here is code:
1) Call dialog:
Code:
NBeep.createDialog(NBeep.DIALOG_ERROR, context);
2) NBeep.java
Code:
public class NBeep extends Activity{
public final static int DIALOG_ERROR = 4;
protected Dialog onCreateDialog(int id) {
Dialog dialog;
switch(id) {
case DIALOG_ERROR:
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("Title");
alertDialog.setMessage("Message");
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent intent=new Intent();
intent.setAction("Navi_BeepOff");
sendBroadcast(intent);
finish();
}
});
alertDialog.setCancelable(false);
dialog = alertDialog;//new AlertDialog.Builder(this).setMessage("ERROR! This is a global dialog\n Brought to you by Sherif").create();
break;
default:
dialog = null;
}
return dialog;
}
[user=439709]@override[/user]
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
showDialog(DIALOG_ERROR);
}
public static void createDialog(int dialog, Context context){
Intent myIntent = new Intent(context, NBeep.class);
myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(myIntent);
}
}

app not sending sms

i am trying to send Message at a scheduled time in my app
here is my activty
Code:
case R.id.bSubmitborrowitem:
String b = mDateDisplay.getText().toString();
String c = mTimeDisplay.getText().toString();
String a = b + "-" + c;
String d = tv1.getText().toString();
String e = "hello";
Toast.makeText(getApplicationContext(), a,
Toast.LENGTH_LONG).show();
//*************coding of sms start here***********************//
// TODO Auto-generated method stub
String pick_no;
pick_no=d;
if(d.length()!=0&& e.length()!=0)
{
Intent b_Intent=new Intent();
b_Intent.setAction(MyAlarmService.ACTION);
b_Intent.putExtra("RQS", MyAlarmService.RQS_STOP_SERVICE);
Intent myIntent=new Intent(this,MyAlarmService.class);
myIntent.setAction(Intent.ACTION_SEND);
Bundle bundle=new Bundle();
bundle.putString("sms_number", d);
bundle.putCharSequence("body", e);
bundle.putString("contact_choose", d);
myIntent.putExtras(bundle);
pi=PendingIntent.getService(this, 0, myIntent,1);
pn.add(PendingIntent.getBroadcast(this, 0, b_Intent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK));
pn.add(pi);
AlarmManager alarm_manager=(AlarmManager)getSystemService(Context.ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.DAY_OF_MONTH, mDay);
calendar.set(Calendar.MONTH, mMonth);
calendar.set(Calendar.YEAR, mYear);
calendar.set(Calendar.HOUR_OF_DAY, hour);
calendar.set(Calendar.MINUTE, mminute);
calendar.clear();
alarm_manager.set(AlarmManager.RTC_WAKEUP,calendar.getTimeInMillis(),pi);
Toast.makeText(this, "your msg will be sending at "+hour+" hours and "+mminute+" min", Toast.LENGTH_LONG).show();
//*************coding of sms start here***********************//
And here is Service class
Code:
public class MyAlarmService extends Service {
String To,message_body,pick;
NotifyServiceReceiver notifyServiceReceiver;
final static String ACTION = "NotifyServiceAction";
final static String STOP_SERVICE = "";
final static int RQS_STOP_SERVICE = 1;
private static final int MY_NOTIFICATION_ID=1;
private NotificationManager notificationManager;
private Notification myNotification;
SmsManager sms;
[user=439709]@override[/user]
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
[user=439709]@override[/user]
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
Toast.makeText(this, "Service created", Toast.LENGTH_LONG).show();
notifyServiceReceiver = new NotifyServiceReceiver();
}
[user=439709]@override[/user]
public void onDestroy() {
// TODO Auto-generated method
super.onDestroy();
Toast.makeText(getBaseContext(), "destroy",
Toast.LENGTH_SHORT).show();
}
private void CancelService() {
// TODO Auto-generated method stub
}
[user=439709]@override[/user]
public int onStartCommand(Intent intent, int flags, int startId) {
// TODO Auto-generated method stub
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(ACTION);
registerReceiver(notifyServiceReceiver, intentFilter);
Bundle bundle=intent.getExtras();
Toast.makeText(this, "service Started", Toast.LENGTH_LONG).show();
String SENT = "SMS_SENT";
String DELIVERED = "SMS_DELIVERED";
PendingIntent sentPI = PendingIntent.getBroadcast(this, 0,
new Intent(SENT), 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
new Intent(DELIVERED), 0);
//---when the SMS has been sent---
registerReceiver(new BroadcastReceiver(){
[user=439709]@override[/user]
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode())
{
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "SMS sent",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
Toast.makeText(getBaseContext(), "Generic failure",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
Toast.makeText(getBaseContext(), "No service",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
Toast.makeText(getBaseContext(), "Null PDU",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
Toast.makeText(getBaseContext(), "Radio off",
Toast.LENGTH_SHORT).show();
break;
}
}
}, new IntentFilter(SENT));
registerReceiver(new BroadcastReceiver(){
[user=439709]@override[/user]
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode())
{
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "SMS delivered",
Toast.LENGTH_SHORT).show();
break;
case Activity.RESULT_CANCELED:
Toast.makeText(getBaseContext(), "SMS not delivered",
Toast.LENGTH_SHORT).show();
break;
}
}
}, new IntentFilter(DELIVERED));
sms = SmsManager.getDefault();
sms.sendTextMessage(bundle.getString("sms_number"), null,(String) bundle.getCharSequence("body") , sentPI, deliveredPI);
notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
myNotification = new Notification(R.drawable.ic_launcher, "Notification!",System.currentTimeMillis());
Context context = getApplicationContext();
String notificationTitle = "Exercise of Notification!";
String notificationText = "Message Notification";
PendingIntent myIntent1 = PendingIntent.getActivity(context, 0, new Intent(Intent.ACTION_VIEW, People.CONTENT_URI), 0);
myNotification.defaults |= Notification.DEFAULT_SOUND;
myNotification.flags |= Notification.FLAG_AUTO_CANCEL;
myNotification.setLatestEventInfo(context,notificationTitle,notificationText, myIntent1);
notificationManager.notify(MY_NOTIFICATION_ID, myNotification);
Toast.makeText(this, "your msg will be sending at ", Toast.LENGTH_LONG).show();
return START_STICKY;
}
[user=439709]@override[/user]
public boolean onUnbind(Intent intent) {
// TODO Auto-generated method stub
return super.onUnbind(intent);
}
public class NotifyServiceReceiver extends BroadcastReceiver{
[user=439709]@override[/user]
public void onReceive(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
int rqs = arg1.getIntExtra("RQS", 0);
if (rqs == RQS_STOP_SERVICE){
stopSelf();
}
}
}
}
everything is fine.. there is no error in code. even the toast come up when i press the submit button..
but it is not sending message .. plzz help
Edit1 app is sending sms now but not on schedule time . it is sending sms instantly
I know this may be a silly question but did you add the proper permissions to your manifest for sending sms?
zalez said:
I know this may be a silly question but did you add the proper permissions to your manifest for sending sms?
Click to expand...
Click to collapse
yes i already added the permission.. check the edit in the main post. it is sending sms but not at schedule time.
This is how I did mine:
MainActivity button click event (or some other event):
Code:
//Now let's set up the alarm
Intent intent = new Intent(MainActivity.this, AlarmReceiver.class);
PendingIntent sender = PendingIntent.getBroadcast(MeterMaid.this,
0, intent, 0);
// We want the alarm to go off 30 seconds from now. Calendar.MINUTE
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(SECONDS_OR_MINUTES, (picker.getValue() - REMINDER_OFFSET));
// Schedule the alarm!
am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), sender);
And my service to receive the alarm:
Code:
public class AlarmReceiver extends BroadcastReceiver
{
private int SIMPLE_NOTFICATION_ID;
[user=439709]@override[/user]
public void onReceive(Context context, Intent intent)
{
NotificationManager manger = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.meter128, "expiration warning", System.currentTimeMillis());
//intent.putExtra("Ringtone", Uri.parse("file:///sdcard/test.mp3"));
intent.putExtra("vibrationPatern", new long[] { 200, 300 });
intent.putExtra("Testtone", RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM));
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), 0);
notification.setLatestEventInfo(context, "Time is up!", "Your time is about to expire!!", contentIntent);
notification.flags = Notification.FLAG_INSISTENT;
notification.sound = (Uri) intent.getParcelableExtra("Testtone"); //Uri.parse("file:///sdcard/test.mp3"); //
notification.vibrate = (long[]) intent.getExtras().get("vibrationPatern");
// The PendingIntent to launch our activity if the user selects this notification
manger.notify(SIMPLE_NOTFICATION_ID, notification);
}
}

Categories

Resources