Search Results

Search found 85 results on 4 pages for 'pendingintent'.

Page 1/4 | 1 2 3 4  | Next Page >

  • AlarmManager triggers PendingIntent too soon

    - by Wezelkrozum
    I've searched for 3 days now but didn't find a solution or similar problem/question anywhere else. Here is the deal: Trigger in 1 hour - works correct Trigger in 2 hours - Goes of in 1:23 Trigger in 1 day - Goes of in ~11:00 So why is the AlarmManager so unpredictable and always too soon? Or what am I doing wrong? And is there another way so that it could work correctly? This is the way I register my PendingIntent in the AlarmManager (stripped down): AlarmManager alarmManager = (AlarmManager)parent.getSystemService(ALARM_SERVICE); Intent myIntent = new Intent(parent, UpdateKlasRoostersService.class); PendingIntent pendingIntent = PendingIntent.getService(parent, 0, myIntent, PendingIntent.FLAG_UPDATE_CURRENT); //Set startdate of PendingIntent so it triggers in 10 minutes Calendar start = Calendar.getInstance(); start.setTimeInMillis(SystemClock.elapsedRealtime()); start.add(Calendar.MINUTE, 10); //Set interval of PendingIntent so it triggers every day Integer interval = 1*24*60*60*1000; //Cancel any similar instances of this PendingIntent if already scheduled alarmManager.cancel(pendingIntent); //Schedule PendingIntent alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, start.getTimeInMillis(), interval, pendingIntent); //Old way I used to schedule a PendingIntent, didn't seem to work either //alarmManager.set(AlarmManager.RTC_WAKEUP, start.getTimeInMillis(), pendingIntent); It would be awesome if anyone has a solution. Thanks for any help! Update: 2 hours ago it worked to trigger it with an interval of 2 hours, but after that it triggered after 1:20 hours. It's getting really weird. I'll track the triggers down with a logfile and post it here tomorrow. Update: The PendingIntent is scheduled to run every 3 hours. From the log's second line it seems like an old scheduled PendingIntent is still running: [2012-5-3 2:15:42 519] Updating Klasroosters [2012-5-3 4:15:15 562] Updating Klasroosters [2012-5-3 5:15:42 749] Updating Klasroosters [2012-5-3 8:15:42 754] Updating Klasroosters [2012-5-3 11:15:42 522] Updating Klasroosters But, I'm sure I cancelled the scheduled PendingIntent's before I schedule a new one. And every PendingIntent isn't recreated in the same way, so it should be exactly the same. If not , this threads question isn't relevant anymore.

    Read the article

  • PendingIntent in Widget + TaskKiller

    - by YaW
    Hi, I've developed an Application (called Instant Buttons) and the app has a widget feature. This widget uses PendingIntent for the onClick of the widget. My PendingIntent code is something like this: Intent active = new Intent(context, InstantWidget.class); active.setAction(String.valueOf(appWidgetId)); active.putExtra("blabla", blabla); //Some data PendingIntent actionPendingIntent = PendingIntent.getBroadcast(context, 0, active, 0); actionPendingIntent.cancel(); actionPendingIntent = PendingIntent.getBroadcast(context, 0, active, 0); remoteViews.setOnClickPendingIntent(R.id.button, actionPendingIntent); The onReceive gets the intent and do some stuff with the MediaPlayer class to reproduce a sound. I have reports from some users that the widgets stop working after a while and with some research i've discovered is because the Task Killers. It seems that when you kill the app in the TaskKiller, the PendingIntent is erased from memory, so when you click the widget, it doesn't know what to do. Is there any solution for this? Is my code wrong or something or it's the default behavior of the PendingIntent? Is there something I can use to avoid the TaskKiller to stop my widgets from working?? Greetings.

    Read the article

  • Multiple calls to AlarmManager.setRepeating deliver the same Intent/PendingIntent extra values, but

    - by Chris Boyle
    Solved while writing this question, but posting in case it helps anyone: I'm setting multiple alarms like this, with different values of id: AlarmManager alarms = (AlarmManager)context.getSystemService( Context.ALARM_SERVICE); Intent i = new Intent(MyReceiver.ACTION_ALARM); // "com.example.ALARM" i.putExtra(MyReceiver.EXTRA_ID, id); // "com.example.ID", 2 PendingIntent p = PendingIntent.getBroadcast(context, 0, i, 0); alarms.setRepeating(AlarmManager.RTC_WAKEUP, nextMillis, 300000, p); // 5 mins ...and receiving them like this: public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(ACTION_ALARM)) { // It's time to sound/show an alarm final long id = intent.getLongExtra(EXTRA_ID, -1); The alarm is delivered to my receiver at the right times, but often with EXTRA_ID set to the wrong value: it's a value that I have used at some point, just not the one that I wanted delivered at that particular time.

    Read the article

  • getExtra from Intent launched from a pendingIntent

    - by spagi
    Hi. I am trying to make some alarms after the user selects something with a time from a list and create a notification for it at the given time. My problem is that the "showname" that a putExtra on my Intent cant be received at the broadcast receiver. It always get null value. This is the way I do it for most of my intents but I think this time maybe because of the pendingIntent or the broadcastReceiver something need to be done differentelly. Thank you The function that sends the Intent through the pending intent public void setAlarm(String showname,String time) { String[] hourminute=time.split(":"); String hour = hourminute[0]; String minute = hourminute[1]; Calendar rightNow = Calendar.getInstance(); rightNow.set(Calendar.HOUR_OF_DAY, Integer.parseInt(hour)); rightNow.set(Calendar.MINUTE, Integer.parseInt(minute)); rightNow.set(Calendar.SECOND, 0); long t=rightNow.getTimeInMillis(); long t1=System.currentTimeMillis(); try { Intent intent = new Intent(this, alarmreceiver.class); Bundle c = new Bundle(); c.putString("showname", showname);//This is the value I want to pass intent.putExtras(c); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 12345, intent, 0); AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); alarmManager.set(AlarmManager.RTC_WAKEUP, rightNow.getTimeInMillis(),pendingIntent); //Log.e("ALARM", "time of millis: "+System.currentTimeMillis()); Toast.makeText(this, "Alarm set", Toast.LENGTH_LONG).show(); } catch (Exception e) { Log.e("ALARM", "ERROR IN CODE:"+e.toString()); } } And this is the receiving end public class alarmreceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { // Toast.makeText(context, "Alarm worked.", Toast.LENGTH_LONG).show(); Bundle b = intent.getExtras(); String showname=b.getString("showname");//This is where I suppose to receive it but its null NotificationManager manger = (NotificationManager) context .getSystemService(context.NOTIFICATION_SERVICE); Notification notification = new Notification(R.drawable.icon, "TVGuide ?pe???µ?s?", System.currentTimeMillis()); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(context, tvguide.class), 0); notification.setLatestEventInfo(context, "?? ?????aµµa ?e????se", showname, contentIntent); notification.flags = Notification.FLAG_ONLY_ALERT_ONCE; notification.sound = Uri.parse("file:///sdcard/dominating.mp3"); notification.vibrate = new long[]{100, 250, 100, 500}; manger.notify(1, notification); } }

    Read the article

  • PendingIntent from notification and application history conflicts

    - by synic
    I'm creating a notification with something similar to the following: Intent ni = new Intent(this, SomeActivity.class); ni.putExtra("somestring", "somedata"); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, ni, PendingIntent.FLAG_UPDATE_CURRENT|PendingIntent.FLAG_ONE_SHOT); Context context = getApplicationContext(); notification.setLatestEventInfo(context, res.getString(R.string.app_name), text, contentIntent); The key here is the extra data on the Intent for the notification. Once I click on the notification and it brings up SomeActivity, it brings up the activity and the extra data is available. However, if I exit the app, hold the home button until the recent activities list comes up, and choose to open the app again, the extra data is still passed. Is there a way I can make this data get passed only if the app is opened via the Notification, and not from the recent activities list?

    Read the article

  • PendingIntent sent from a notication.

    - by totem
    Hi, What im trying to accomplish is to send a notification through the notification manager that once clicked will do something in the application only if its currently running. i have tried to use: notification.contentIntent = PendingIntent.getActivity(this, nNotificationCounter, Someintent, PendingIntent.FLAG_NO_CREATE) Which allways caused an exception once trying to use the notify. I switched to: Notification notification = new Notification(icon, tickerText, when); RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.some_notification); contentView.setTextViewText(R.id.title, sTitle); contentView.setTextViewText(R.id.text, sText); notification.contentView = contentView; notification.defaults |= Notification.DEFAULT_SOUND; notification.number = nNotificationCounter; Intent notificationIntent = new Intent(this, MainWindow.class).setAction(ACTION_RESET_MESSGE_COUNTER); notification.contentIntent = PendingIntent.getBroadcast(this, nNotificationCounter, notificationIntent, 0); and although this code doesn't cause an exception. it doesnt call my BroadcastReceiver which is defined as follows: public class IncomingReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(ACTION_RESET_MESSGE_COUNTER)) { System.out.println("GOT THE INTENT"); return; } } } and set in the onCreate: IntentFilter filter = new IntentFilter(ACTION_RESET_MESSGE_COUNTER); IncomingReceiver receiver = new IncomingReceiver(); context.registerReceiver(receiver, filter); Does anyone see something wrong with the code? Or how would i go about to get messages when the notification is clicked, but not create any activity if it isn't already created. edit: added the intent creation and notification creation. Thanks, Tom

    Read the article

  • I need help with Widget and PendingIntents

    - by YaW
    Hi, I've asked here a question about Task Killers and widgets stop working (SO Question) but now, I have reports of user that they don't use any Task Killer and the widgets didn't work after a while. I have a Nexus One and I don't have this problem. I don't know if this is a problem of memory or something. Based on the API: A PendingIntent itself is simply a reference to a token maintained by the system describing the original data used to retrieve it. This means that, even if its owning application's process is killed, the PendingIntent itself will remain usable from other processes that have been given it. So, I don't know why widget stop working, if Android doesn't kill the PendingIntent by itself, what's the problem? This is my manifest code: <receiver android:name=".widget.InstantWidget" android:label="@string/app_name"> <intent-filter> <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> </intent-filter> <meta-data android:name="android.appwidget.provider" android:resource="@xml/widget_provider" /> </receiver> And the widget code: public class InstantWidget extends AppWidgetProvider { public static ArrayList<Integer> alWidgetsId = new ArrayList<Integer>(); private static final String PREFS_NAME = "com.cremagames.instant.InstantWidget"; private static final String PREF_PREFIX_NOM = "nom_"; private static final String PREF_PREFIX_RAW = "raw_"; /** * Esto se llama cuando se crea el widget. Metemos en las preferencias los valores de nombre y raw para tenerlos en proximos reboot. * @param context * @param appWidgetManager * @param appWidgetId * @param nombreSound * @param rawSound */ static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId, String nombreSound, int rawSound){ //Guardamos en las prefs los valores SharedPreferences.Editor prefs = context.getSharedPreferences(PREFS_NAME, 0).edit(); prefs.putString(PREF_PREFIX_NOM + appWidgetId, nombreSound); prefs.putInt(PREF_PREFIX_RAW + appWidgetId, rawSound); prefs.commit(); //Actualizamos la interfaz updateWidgetGrafico(context, appWidgetManager, appWidgetId, nombreSound, rawSound); } /** * Actualiza la interfaz gráfica del widget (pone el nombre y crea el intent con el raw) * @param context * @param appWidgetManager * @param appWidgetId * @param nombreSound * @param rawSound */ private static void updateWidgetGrafico(Context context, AppWidgetManager appWidgetManager, int appWidgetId, String nombreSound, int rawSound){ RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget); //Nombre del Button remoteViews.setTextViewText(R.id.tvWidget, nombreSound); //Creamos el PendingIntent para el onclik del boton Intent active = new Intent(context, InstantWidget.class); active.setAction(String.valueOf(appWidgetId)); active.putExtra("sonido", rawSound); PendingIntent actionPendingIntent = PendingIntent.getBroadcast(context, 0, active, 0); actionPendingIntent.cancel(); actionPendingIntent = PendingIntent.getBroadcast(context, 0, active, 0); remoteViews.setOnClickPendingIntent(R.id.btWidget, actionPendingIntent); appWidgetManager.updateAppWidget(appWidgetId, remoteViews); } public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); //Esto se usa en la 1.5 para que se borre bien el widget if (AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action)) { final int appWidgetId = intent.getExtras().getInt( AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) { this.onDeleted(context, new int[] { appWidgetId }); } } else { //Listener de los botones for(int i=0; i<alWidgetsId.size(); i++){ if (intent.getAction().equals(String.valueOf(alWidgetsId.get(i)))) { int sonidoRaw = 0; try { sonidoRaw = intent.getIntExtra("sonido", 0); } catch (NullPointerException e) { } MediaPlayer mp = MediaPlayer.create(context, sonidoRaw); mp.start(); mp.setOnCompletionListener(completionListener); } } super.onReceive(context, intent); } } /** Al borrar el widget, borramos también las preferencias **/ public void onDeleted(Context context, int[] appWidgetIds) { for(int i=0; i<appWidgetIds.length; i++){ //Recogemos las preferencias SharedPreferences.Editor prefs = context.getSharedPreferences(PREFS_NAME, 0).edit(); prefs.remove(PREF_PREFIX_NOM + appWidgetIds[i]); prefs.remove(PREF_PREFIX_RAW + appWidgetIds[i]); prefs.commit(); } super.onDeleted(context, appWidgetIds); } /**Este método se llama cada vez que se refresca un widget. En nuestro caso, al crearse y al reboot del telefono. Al crearse lo único que hace es guardar el id en el arrayList Al reboot, vienen varios ID así que los recorremos y guardamos todos y también recuperamos de las preferencias el nombre y el sonido*/ public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { for(int i=0; i<appWidgetIds.length; i++){ //Metemos en el array los IDs de los widgets alWidgetsId.add(appWidgetIds[i]); //Recogemos las preferencias SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, 0); String nomSound = prefs.getString(PREF_PREFIX_NOM + appWidgetIds[i], null); int rawSound = prefs.getInt(PREF_PREFIX_RAW + appWidgetIds[i], 0); //Si están creadas, actualizamos la interfaz if(nomSound != null){ updateWidgetGrafico(context, appWidgetManager, appWidgetIds[i], nomSound, rawSound); } } } MediaPlayer.OnCompletionListener completionListener = new MediaPlayer.OnCompletionListener(){ public void onCompletion(MediaPlayer mp) { if(mp != null){ mp.stop(); mp.release(); mp = null; } } }; } Sorry for the comments in Spanish. I have the possibility to put differents widgets on the desktop, that's why I use the widgetId as the "unique id" for the PendingIntent. Any ideas please? The 70% of the functionality of my app is the widgets, and it isn't working for some users :( Thanks in advance and sorry for my English.

    Read the article

  • when would you use PendingIntent?

    - by Moshik
    Hi, I tried to understand from the api the porpese of PendingIntent, coz sometimes some method i use requires this, i still didnt get the idea right, anyone could exaplin? why cant i juse use context? thanks, moshik

    Read the article

  • Dropping PendingIntents

    - by Jeremy Edwards
    Is it ok to drop PendingIntents in android if they are never used. Such as in an AppWidgetProvider where a PendingIntent that was never used be overwritten by a new PendingIntent. Or should we call cancel on all unused PendingIntents to clean up memory appropriately?

    Read the article

  • Android: Adding data to Intent fails to load Activity

    - by DroidIn.net
    I have a widget that supposed to call an Activity of the main app when the user clicks on widget body. My setup works for a single widget instance but for a second instance of the same widget the PendingIntent gets reused and as result the vital information that I'm sending as extra gets overwritten for the 1st instance. So I figured that I should pass widget ID as Intent data however as soon as I add Intent#setData I would see in the log that 2 separate Intents are appropriately fired but the Activity fails to pick it up so basically Activity will not come up and nothing happens (no error or warning ether) Here's how the activity is setup in the Manifest: <activity android:name=".SearchResultsView" android:label="@string/search_results" <intent-filter> <action android:name="bostone.android.search.RESULTS" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> And here's code that is setup for handling the click Intent di = new Intent("bostone.android.search.RESULTS"); di.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // if line below is commented out - the Activity will start di.setData(ContentUris.withAppendedId(Uri.EMPTY, widgetId)); di.putExtra("URL", url); views.setOnClickPendingIntent(R.id.widgetContent, PendingIntent.getActivity(this, 0, di, 0)); The main app and the widget are packaged as 2 separate APK each in its own package and Manifest

    Read the article

  • Android repeating alarm not working

    - by erdomester
    This works fine: Intent intent = new Intent(HelloAndroid2.this, AlarmReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(HelloAndroid2.this, 0, intent, PendingIntent.FLAG_ONE_SHOT); AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (12 * 1000), pendingIntent); This doesn't work. I hear the alarm only time. alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (12 * 1000), 3 * 1000, pendingIntent); I have also tried this, no luck: Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); calendar.add(Calendar.SECOND, 5); alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 7000, pendingIntent); What is the problem?

    Read the article

  • Android alarm not working

    - by erdomester
    I've been struggling with this for hours. I've also checked the documentation and several topics. I found this code in two topics, both guys said the code was working perfectly, but not on my computer. The first Toast appears, but the second one never. What is wrong? public class HelloAndroid2 extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Intent intent = new Intent(this, AlarmReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_ONE_SHOT); AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (10 * 1000), pendingIntent); Toast.makeText(this, "Alarm set", Toast.LENGTH_LONG).show(); } public final class AlarmReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Toast.makeText(context, "Alarm worked.", Toast.LENGTH_LONG).show(); } } }

    Read the article

  • BroadcastReceiver not receiving an alarm's broadcast

    - by juanjux
    I have a code that sets a new repeating alarm (on production I'll use a inexactRepeating), but the BroadCastReceiver I've registered for handling it is not being called. Here is the code where I set the alarm: newAlarmPeriod = 5000; // For debugging Intent alarmIntent = new Intent(this, GroupsCheckAlarmReceiver.class); PendingIntent sender = PendingIntent.getBroadcast(this, Constants.CHECK_ALARM_CODE, alarmIntent, 0); AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + newAlarmPeriod, newAlarmPeriod, sender); It seems to work and it triggers and alarm every five seconds, as seen in the output of "adb shell dumpsys alarm": DUMP OF SERVICE alarm: Current Alarm Manager state: Realtime wakeup (now=1269941046923): RTC_WAKEUP #1: Alarm{43cbac58 type 0 android} type=0 when=1269997200000 repeatInterval=0 count=0 operation=PendingIntent{43bb1738: PendingIntentRecord{43bb1248 android broadcastIntent}} RTC_WAKEUP #0: Alarm{43ce30e0 type 0 com.almarsoft.GroundhogReader} type=0 when=1269941049555 repeatInterval=5000 count=1 operation=PendingIntent{43d990c8: PendingIntentRecord{43d49108 com.almarsoft.GroundhogReader broadcastIntent}} RTC #1: Alarm{43bfc250 type 1 android} type=1 when=1269993600000 repeatInterval=0 count=0 operation=PendingIntent{43c5a618: PendingIntentRecord{43c4f048 android broadcastIntent}} RTC #0: Alarm{43d67dd8 type 1 android} type=1 when=1269941100000 repeatInterval=0 count=0 operation=PendingIntent{43c4e0f0: PendingIntentRecord{43c4f6c8 android broadcastIntent}} Broadcast ref count: 0 Alarm Stats: android 24390ms running, 0 wakeups 80 alarms: act=android.intent.action.TIME_TICK flg=0x40000004 com.almarsoft.GroundhogReader 26ms running, 2 wakeups 2 alarms: flg=0x4 cmp=com.almarsoft.GroundhogReader/.GroupsCheckAlarmReceiver But for some reason my BroadCastReceiver is not being called when the alarm is triggered. I've declared it on the Manifest: <receiver android:name=".GroupsCheckAlarmReceiver" /> And this is the abbreviated code: public class GroupsCheckAlarmReceiver extends BroadcastReceiver{ @Override public void onReceive(Context context, Intent intent) { Toast.makeText(context, "XXX Alarm worked.", Toast.LENGTH_LONG).show(); Log.d("XXX", "GroupsCheckAlarmReceiver.onReceive"); }

    Read the article

  • Android - I can't make a widget clickable to launch an intent

    - by Daniele
    Hi all. I am new to Android development. I have developed a very simple widget that was meant to interact with the user via an ImageButton. What I am trying to do now is as follows. When a user taps the button (after adding the widget to their home screen), I want the phone to dial a certain telephone number. A sort of speed dial for your home screen. Unfortunately when I tap the button nothing happens. This is the body of my SpeedDialAppWidgetProvider.onUpdate method: Log.d("", "beginning of onUpdate"); final int N = appWidgetIds.length; for (int i=0; i<N; i++) { int appWidgetId = appWidgetIds[i]; Log.d("", "dealing with appWidgetId: " + appWidgetId); // Create an Intent to launch ExampleActivity Intent dialIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:1234567")); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, dialIntent, 0); Log.d("", "pendingIntent classname " + pendingIntent.getClass().getName()); // Get the layout for the App Widget and attach an on-click listener to the button RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.speed_dial_appwidget); remoteViews.setOnClickPendingIntent(R.id.dial_icon, pendingIntent); Log.d("", "remoteViews classname " + remoteViews.getClass().getName()); // Tell the AppWidgetManager to perform an update on the current App Widget appWidgetManager.updateAppWidget(appWidgetId, remoteViews); Log.d("", "end of onUpdate"); I can see the method is called and the result of the logging makes sense. The speed_dial_appwidget.xml file is like this: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" androidrientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" > <ImageButton id="@+id/dial_icon" android:src="@drawable/speed_dial" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout> Can you please help me with this? Thanks in advance, Dan

    Read the article

  • [Android] Launching activity from widget

    - by Steve H
    Hi, I'm trying to do something which really ought to be quite easy, but it's driving me crazy. I'm trying to launch an activity when a home screen widget is pressed, such as a configuration activity for the widget. I think I've followed word for word the tutorial on the Android Developers website, and even a few unofficial tutorials as well, but I must be missing something important as it doesn't work. Here is the code: public class VolumeChangerWidget extends AppWidgetProvider { public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds){ final int N = appWidgetIds.length; for (int i=0; i < N; i++) { int appWidgetId = appWidgetIds[i]; Log.d("Steve", "Running for appWidgetId " + appWidgetId); Toast.makeText(context, "Hello from onUpdate", Toast.LENGTH_SHORT); Log.d("Steve", "After the toast line"); Intent intent = new Intent(context, WidgetTest.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget); views.setOnClickPendingIntent(R.id.button, pendingIntent); appWidgetManager.updateAppWidget(appWidgetId, views); } } } When adding the widget to the homescreen, Logcat shows the two debugging lines, though not the Toast. (Any ideas why not?) However, more vexing is that when I then click on the button with the PendingIntent associated with it, nothing happens at all. I know the "WidgetTest" activity can run because if I set up an Intent from within the main activity, it launches fine. In case it matters, here is the Android Manifest file: <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.steve" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".Volume_Change_Program" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".WidgetTest" android:label="@string/hello"> <intent_filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent_filter> </activity> <receiver android:name=".VolumeChangerWidget" > <intent-filter> <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> </intent-filter> <meta-data android:name="android.appwidget.provider" android:resource="@xml/volume_changer_info" /> </receiver> </application> <uses-sdk android:minSdkVersion="3" /> Is there a way to test where the fault is? I.e. is the fault that the button isn't linked properly to the PendingIntent, or that the PendingIntent or Intent isn't finding WidgetTest.class, etc? Thanks very much for your help! Steve

    Read the article

  • Creating a bitmask parameter for a function or method

    - by synic
    I noticed a lot of Android functions have a parameter that you can pass in that's a bitmask, for different options, like on PendingIntent, you can pass in things like you can call getActivity() with PendingIntent.FLAG_CANCEL_CURRENT|PendingIntent.FLAG_NO_CREATE. I'm wondering how I can create a function that has a parameter like this?

    Read the article

  • Event OnClick for a button in a custom notification

    - by Simone
    I have a custom notification with a button. To set the notification and use the event OnClick on my button I've used this code: //Notification and intent of the notification Notification notification = new Notification(R.drawable.stat_notify_missed_call, "Custom Notification", System.currentTimeMillis()); Intent mainIntent = new Intent(getBaseContext(), NotificationActivity.class); PendingIntent pendingMainIntent = PendingIntent.getActivity(getBaseContext(), 0, mainIntent , 0); notification.contentIntent = pendingMainIntent; //Remoteview and intent for my button RemoteViews notificationView = new RemoteViews(getBaseContext().getPackageName(), R.layout.remote_view_layout); Intent activityIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:190")); PendingIntent pendingLaunchIntent = PendingIntent.getActivity(getBaseContext(), 0, activityIntent, PendingIntent.FLAG_UPDATE_CURRENT); notificationView.setOnClickPendingIntent(R.id.button1, pendingLaunchIntent); notification.contentView = notificationView; notificationManager.notify(CUSTOM_NOTIFICATION_ID, notification); With this code I've a custom notification with my custom layout...but I can't click the button! every time I try to click the button I click the entire notification and so the script launch the "mainIntent" instead of "activityIntent". I have read in internet that this code doesn't work on all terminals. I have tried it on the emulator and on an HTC Magic but I have always the same problem: I can't click the button! My code is right? someone can help me? Thanks, Simone

    Read the article

  • How to stop LocationManager to broadcast the location to BroadcastManager.

    - by SKuamr
    Hi i added one Broadcast listener for LocationManager [GPS_PROVIDER] with a pending intent. so now when i close my application on phone location manager is updating the broadcast listener perfectly... so this is working fine. Now issue is, i want to stop the LocationManager to update the Broadcast listener... but i am not able to do so... i am again running the application and using locationManager.removeUpdates function to stop it but it still updating the location to Broadcast Manager. Please help me out... its very urgent... Thanks in advance.. Started the Location Manager. Intent intent = new Intent("com.test.geoL.RECEIVE"); //Broadcast Receiver Action PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(),0, intent, 0); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, pendingIntent);

    Read the article

  • Activity triggered by a click on a Notification

    - by Zelig63
    From a Service, I trigger a Notification which, when clicked, has to launch an Activity. To do this, I use the following code : notification=new Notification(icone,title,System.currentTimeMillis()); intent=new Intent(getApplicationContext(),myActivity.class); intent.putExtra("org.mypackage.name",true); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); pendingIntent=PendingIntent.getActivity(getApplicationContext(),0,intent,PendingIntent.FLAG_ONE_SHOT); notification.setLatestEventInfo(getApplicationContext(),title,"Message",pendingIntent); notification.flags|=Notification.FLAG_AUTO_CANCEL; ((NotificationManager)contexte.getSystemService(Context.NOTIFICATION_SERVICE)).notify("label,0,notification); When I click on the Notification, the Activity is correctly launched. But it's Intent doesn't contain the extra boolean added with the line intent.putExtra("org.mypackage.name",true);. Does anyone have an idea of this behaviour? I can add that I use Android 4. Thanks in advance for the time you will spend trying to help me.

    Read the article

  • how to find which button has been clicked in app widgets in android?

    - by chrish
    I want to design simple app widget which has two textview and two button for previous/next. I am getting difficult to handle button click in app widget. Actually my desire is,if user click on previous button i want to show previous value and if user click on Next button i want to show next value from database. How to know which button is clicked? here i register button click listener like this public static class UpdateWidgetService extends IntentService { public UpdateWidgetService() { super("UpdateWidgetService"); } @Override protected void onHandleIntent(Intent intent) { AppWidgetManager appWidgetManager = AppWidgetManager .getInstance(this); int incomingAppWidgetId = intent.getIntExtra(EXTRA_APPWIDGET_ID, INVALID_APPWIDGET_ID); if (incomingAppWidgetId != INVALID_APPWIDGET_ID) { updateOneAppWidget(appWidgetManager, incomingAppWidgetId); } } private void updateOneAppWidget(AppWidgetManager appWidgetManager, int appWidgetId) { DatabaseManager dbManager = new DatabaseManager(this); dbManager.open(); String contactNumber, date, status, message; ArrayList<QueuedMessage> listOfQuedMessage = (ArrayList<QueuedMessage>) dbManager .fetchContactNumber(); if (listOfQuedMessage.size() == 0) Log.i("Db", "null"); else{ date = dbManager.fetchDate(); message = dbManager.fetchMessage(); status = dbManager.fetchStatus(); dbManager.closeDatabase(); RemoteViews views = new RemoteViews(this.getPackageName(), R.layout.schdulesms_appwidget_layout); views.setTextViewText(R.id.to_appwidget_saved_data, listOfQuedMessage.get(count).contacNumber); views.setTextViewText(R.id.date_appwidget_saved_data, date); views.setTextViewText(R.id.status_appwidget_saved, status); views.setTextViewText(R.id.message_appwidgset_saved_data, message); **//here i want do** if(button1){ btnNxtClick(views, appWidgetId,listOfQuedMessage.size()); }else{ btPrevClick(views, appWidgetId, listOfQuedMessage.size()); } appWidgetManager.updateAppWidget(appWidgetId, views); } } private void btnNxtClick(RemoteViews views, int appWidgetId,int sizeOfList) { Intent btnNextIntent = new Intent(this, this.getClass()); btnNextIntent.putExtra(EXTRA_APPWIDGET_ID, appWidgetId); PendingIntent btnNextPendingIntent = PendingIntent.getService(this, 0, btnNextIntent, PendingIntent.FLAG_UPDATE_CURRENT); views.setOnClickPendingIntent(R.id.btnNext, btnNextPendingIntent); } private void btPrevClick(RemoteViews views, int appWidgetId,int sizeOfList) { Intent btnNextIntent = new Intent(this, this.getClass()); btnNextIntent.putExtra(EXTRA_APPWIDGET_ID, appWidgetId); PendingIntent btnNextPendingIntent = PendingIntent.getService(this, 0, btnNextIntent, PendingIntent.FLAG_UPDATE_CURRENT); views.setOnClickPendingIntent(R.id.btnPrev, btnNextPendingIntent); } } can anyone help me out from this problem?? thanks

    Read the article

  • Unwanted automated creation of new instances of an activity class

    - by Marko
    I have an activity (called Sender) with the most basic UI, only a button that sends a message when clicked. In the onClickListener I only call this method: private void sendSMS(String msg) { PendingIntent pi = PendingIntent.getActivity(this, 0, new Intent(this, Sender.class), 0); PendingIntent pi = PendingIntent.getActivity(this, 0, myIntent, 0); SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage("1477", null, msg, pi, null); } This works ok, the message is sent but every time a message is sent a new instance of Sender is started on top of the other. If I call sendSMS method three times, three new instances are started. I'm quite new to android so I need some help with this, I only want the same Sender to be on all the time

    Read the article

  • [Android] Pass variable/intent to an activity when launched from a Widget

    - by Pelly
    Hi, Currently within an activity in my application I can call another activity and pass a variable to it in the following manner: Intent myIntent = new Intent(parentView.getContext(), ShowStations.class); myIntent.putExtra("stationName", stations[position].StationName); startActivity(myIntent); This works fine, but now I want to be able to do the same from my Widget. Currently this code works fine for launching a specific activity from my widget: Intent WidgetIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER).setComponent(new ComponentName("grell.com", "grell.com.FavStations")); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, WidgetIntent, 0); updateViews.setOnClickPendingIntent(R.id.widget_main, pendingIntent); So now I am wondering how can I launch the same activity as shown in the first example but also pass through the 'stationName' variable. Any help would be greatly appreciated. Cheers

    Read the article

  • BroadcastReciever doesn't show SMS not Send or Not delivered

    - by user1657111
    While using broadcastreciver for checking sms status, it shows the toast when sms is sent but shows nothing when sms is not sent or delivered (im testing it by putting an abrupt number). the code im using is the one ive seen the most on every site of checking sms delivery status. But my code is only showing the status when sms is sent successfully. Can any one get a hint of what am i doing wrong ? I hav this method in doInBackground() and so obviously im using AsyncTask. Thanks guys public void send_SMS(String list, String msg, AtaskClass task) { String SENT = "SMS_SENT"; String DELIVERED = "SMS_DELIVERED"; SmsManager sms = SmsManager.getDefault(); 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(){ @Override public void onReceive(Context context, Intent arg1) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(context, "SMS sent", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_GENERIC_FAILURE: Toast.makeText(context, "Generic failure", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NO_SERVICE: Toast.makeText(context, "No service", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NULL_PDU: Toast.makeText(context, "Null PDU", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_RADIO_OFF: Toast.makeText(context, "Radio off", Toast.LENGTH_SHORT).show(); break; } } }, new IntentFilter(SENT)); //---when the SMS has been delivered--- registerReceiver(new BroadcastReceiver(){ @Override public void onReceive(Context context, Intent arg1) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(context, "SMS delivered", Toast.LENGTH_SHORT).show(); break; case Activity.RESULT_CANCELED: Toast.makeText(context, "SMS not delivered", Toast.LENGTH_SHORT).show(); break; } } }, new IntentFilter(DELIVERED)); StringTokenizer st = new StringTokenizer(list,","); int count= st.countTokens(); int i =1; count = 1; while(st.hasMoreElements()) { // PendingIntent pi = PendingIntent.getActivity(this,0,new Intent(this, SMS.class),0); String tempMobileNumber = (String)st.nextElement(); //SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage(tempMobileNumber, null, msg , sentPI, deliveredPI); Double cCom = ((double)i/count) * 100; int j = cCom.intValue(); task.doProgress(j); i++; count ++; } // class ends }

    Read the article

1 2 3 4  | Next Page >