Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

test: Reply
 
LinkBack Thread Tools
Old December 19th, 2012, 06:12 AM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Dec 2012
Posts: 2
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with a custom broadcastReciever and AlarmManager

Hello,
i m developping an application for creating , deleting and modifing Tasks with a system alarm manager.
Here is the code snippet where i start a service called 'AlarmService'. The role of this service is to create an AlarmManger and send an intent to a receiver called 'AlarmReceiver'. The role of the receiver is to send notification to the user when the alarm goes off.

[HIGH]
public class CreationTaskActivity extends FragmentActivity {
[...]
Intent intent_alarm = new Intent(CreationTaskActivity.this,AlarmService.clas s);
intent_alarm.putExtra("nomTache", name);
intent_alarm.putExtra("descTache", description);
intent_alarm.putExtra("identifiant",uri.getLastPat hSegment()); intent_alarm.putExtra("declencher",gc.getTimeInMil lis());
CreationTaskActivity.this.startService(intent_alar m);
[/HIGH]AlarmService.java:
[HIGH]
public class AlarmService extends IntentService {

public AlarmService() {
super("AlarmService");
}

@Override
protected void onHandleIntent(Intent intent) {

Log.d("alarmservice", "cool");
PendingIntent sender = PendingIntent.getBroadcast(this, 0,intent, 0);
Intent new_intent = new Intent(this, AlarmReceiver.class);
new_intent.putExtra("nomTache", intent.getStringExtra("nomTache"));
new_intent.putExtra("descTache", intent.getStringExtra("descTache"));
new_intent.putExtra("identifiant",intent.getString Extra("identifiant"));
new_intent.setAction("com.dummies.android.taski_rl a0904.alarmaction");
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, intent.getLongExtra("declencher",
System.currentTimeMillis()), sender);
sendBroadcast(new_intent);
}
[/HIGH]AlarmReceiver.java:
[HIGH]
public class AlarmReceiver extends BroadcastReceiver {

private final String ALARM = "com.dummies.android.taski_rla0904.alarmaction ";
@Override
public void onReceive(Context ctx, Intent intent) {

//PowerManager pm = (PowerManager) ctx.getSystemService(Context.POWER_SERVICE);
//PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "");
//wl.acquire();
if(intent.getAction().equals(ALARM)){
NotificationCompat.Builder mbuilder = new NotificationCompat.Builder(ctx);
mbuilder.setSmallIcon(R.drawable.ic_launcher);
mbuilder.setContentTitle(intent.getStringExtra("co mTache"));
mbuilder.setContentText(intent.getStringExtra("des cTache"));
String id = intent.getStringExtra("identifiant");
Log.d("taski","alarmreceive");
NotificationManager mNotificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE) ;
mNotificationManager.notify(Integer.parseInt(id), mbuilder.build());
}
//wl.release();
}

}
[/HIGH]AndroidManifest.xml:
[HIGH]
[...]
<receiver android:name=".AlarmReceiver">
<intent-filter>
<action android:name="com.dummies.android.taski_rla0904.al armaction" />
</intent-filter>
</receiver>
<service android:name=".AlarmService" />
[/HIGH]

When i run the application on the emulator, i have this exception:
java.lang.IllegalArgumentException: Enable to start receiver .java.lang.IllegalArgumentException:contentIntent required....

Advertisements
Rokia is offline  
Reply With Quote
sponsored links
Old December 19th, 2012, 06:51 AM   #2 (permalink)
New Member
Thread Author (OP)
 
Join Date: Dec 2012
Posts: 2
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

I just have found the solution. what i have to do is to set contentIntent to the builder of notification. just like this:
[HIGH]
Intent notifyIntent =new Intent(ctx,ResultActivity.class);
notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TAS K | IntentCompat.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent notifyPIntent =PendingIntent.getActivity(ctx,0,notifyIntent,Pend ingIntent.FLAG_UPDATE_CURRENT);
Puts the PendingIntent into the notification builder
mbuilder.setContentIntent(notifyPIntent);
[/HIGH]
now i obtain the icon of notification . but when i click on, that doesn't do anything.
have i implement the ResultActivity too?
Rokia is offline  
Reply With Quote
Reply


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 07:25 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.