android programming question - Android Software Development

i'm not sure if this is the right place to ask this, so please direct me to the correct place if this is wrong.
I have an app that is constantly updated a notification in the status bar (changing the icon and updated text in the expanded view). The problem I am having is that when it updates the notification it will close the window I am in for certain actions. For example, if I am looking through my apps when it updates it will close that and take me to the home screen, if I am searching for something in the market it will close the search history, etc. Is there a way to have it update the icon and text in the background and not effect any currently running activity?
here is my notification code:
public void displayNotification(String msg)
{
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification_layout);
settings = context.getSharedPreferences(PREFS_NAME, 0);
statColor = settings.getInt("txtColor", Color.BLACK);
contentView.setTextColor(R.id.text, statColor);
contentView.setTextColor(R.id.text2, statColor);
contentView.setTextColor(R.id.text3, statColor);
contentView.setTextViewText(R.id.text, "some text");
contentView.setTextViewText(R.id.text2, "some more text");
contentView.setTextViewText(R.id.text3, "some more text");
contentView.setImageViewResource(R.id.image, icon[iconIndex]);
Notification notification = new Notification(icon[iconIndex], msg, System.currentTimeMillis());
notification.contentView = contentView;
Intent notificationIntent = new Intent(this, AppService.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 1, notificationIntent, 0);
notification.contentIntent = contentIntent;
manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notification.flags |= Notification.FLAG_NO_CLEAR;
notification.flags |= Notification.FLAG_ONGOING_EVENT;
manager.notify(NOTIFICATION_ID, notification);
}

this thread can be deleted, i fixed it

Considering the

is it possible for you to tell us what you changed to fix it?

Related

Newbie url text download problem

Hi guys,
I am totally new at this. I mean completely raw .
I successfully put together a searchlight project by following a tutorial on youtube.
Now I want to do some work on a project that will fetch information from my employers website into the app. This information will be inform of text and images.
Here's the code I'm using in my attempt to read the remote text:
Code:
try {
URL url = new URL( "fullpath-url-to-file-dot-php" );
URLConnection conn = url.openConnection();
// Get the response
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line = "";
while ((line = rd.readLine()) != null) {
Message lmsg;
lmsg = new Message();
lmsg.obj = line;
lmsg.what = 0;
Context context = getApplicationContext();
CharSequence text = "Hello toast! "+lmsg;
int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(context, text, duration);toast.show();
}
} catch (IOException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
Context context = getApplicationContext();
CharSequence text = "error!";
int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(context, text, duration);toast.show();
}
I admit I barely know what I am doing. My attempt to download a simple line of text from a website url keeps failing.
Anyway, Can you guys give me an idea what I am doing wrong and what I should be doing instead?
Thanks
Update
I found out what the nature of the exception is.
It's a
Code:
java.net.socketexception: permission denied
exception.
Can anyone please shed some light on this for me ?
Did you add the internet permission to your manifest file?
Should be something like
<uses-permission>android.permission.INTERNET</uses-permission>

[Q] Coding help please

Hello all, I am looking for speciffic coding assistance. I have been up for hours trying to figure it out and am having no luck.
I have recently created an Analog clock that I would like to include with a theme I have made. However I am running into an issue with the clock not launching the alarms when pressed. Clock looks and works great, just nothing happens when pressing the clock.
This is what my code looks like as of now:
Code:
MYPACKAGENAME
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.customwidget);
Intent AlarmClockIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER).setComponent(new ComponentName("com.google.android.deskclock", "com.google.android.deskclock.DeskClock"));
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, AlarmClockIntent, 0);
views.setOnClickPendingIntent(R.id.Widget, pendingIntent);
AppWidgetManager.getInstance(context).updateAppWidget(intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS), views);
}
}
Deskclock is the correct one to use right, due to being in 2.2 and all? What am I missing or doing wrong?
All I want it to do is launch the alarms when pressed.....
Any help is appreciated!
Syn
edited coz i forgot to hit code snippet....

dialog with list containing autocomplete text view and a button

I need to create a dialog with a list containing an autocomplete text view and a button for each line. So everything is working except for the autocomplete text view. My program crashes when i tried to call the setAdapter. that's my code:
Code:
private Dialog createSosteDialog() {
final ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
Button conferma_modifiche_soste;
ListView lv;
final Dialog sosteDialog = new Dialog(this);
sosteDialog.setTitle("Lista soste");
sosteDialog.setContentView(R.layout.modifica_soste_dialog_layout);
lv=(ListView)sosteDialog.findViewById(R.id.lista_write);
conferma_modifiche_soste=(Button)sosteDialog.findViewById(R.id.Conferma_modifiche_soste);
AutoCompleteTextView autocomplete=(AutoCompleteTextView)sosteDialog.findViewById(R.id.autocomplete_soste);
String[] fermate_dispositivo = getResources().getStringArray(R.array.Lista_fermate_dispositivo);
ArrayAdapter<String> adapter_autocomplete = new ArrayAdapter<String>(this, R.layout.auto_complete_item, fermate_dispositivo);
autocomplete.setAdapter(adapter_autocomplete); //ERROR WITH THIS LINE!!!!
HashMap<String, String> map;// = new HashMap<String, String>();
int i;
for(i=0;i<soste.length;i++){
map = new HashMap<String, String>();
map.put("sosta", soste[i].getNome());
map.put("orario", soste[i].getStringOrario());
mylist.add(map);
}
SimpleAdapter adapter = new SimpleAdapter(this, mylist, R.layout.lista_soste_item_modifica,
new String[] {"sosta", "orario"},
new int[] {R.id.autocomplete_soste, R.id.lista_soste_cambia_orario});
//new String[] {"from", "to"} imposta le colonne "sosta" e "orario" della map come valori
lv.setAdapter(adapter);
return sosteDialog;
}
I don't know if this is the best way to do that, by the way i've to make a dialog with 1 autocomplete and a button for each line of the list inside that dialog. how could i do that?
thx everyone for your help!
any ideas?
i really need your help, maybe it's a problem with the SimpleAdapter?!?

[SOLVED] Notification not showing in menubar

Hi,
the following code shows a notification in the menu bar. It works if I launch it from an activity, but it doesn't work if I launch it from a service (which runs when I receive BOOT_COMPLETED).
Code:
private void showNotification(String msg) {
String menuText = msg;
String contentTitle = getString(R.string.notify_title_safety);
String contentText = msg;
Context context = getApplicationContext();
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
Notification notification = new Notification(R.drawable.ico_notification, menuText, System.currentTimeMillis());
notification.defaults |= Notification.DEFAULT_SOUND;
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, notification);
}
I can't find any informations about why it works from the activity and not from a service. In fact, in the very first lines of the official docs it is suggested that Services use Notifications instead of Activities (which already have the attention of the user).
Any help/previous experience?
Dumb mistake: the code was not being called because the service name was missing the leading "." in AndroidManifest.xml

Thread to update notification

Hello
I have a problem with my new application development.
I write little task manager and I want to create notification in the status bar that will show the number of the running process in the system.
The notification will update every 60 seconds.
in order to make the update I created new thread in the background wich will update the notification. My problem is that my thread must extents Activity class (to get the number of running proccess).
and I could get this value only when the Activity in "Active" status.
when the activity in the background this value isnt updated.
what can I do?
thanks and sorry for my poor english
this is my example code - refresh every 60 seconds.
I want to change the text "Click here to open Tablet popup manager" to dynamic number of proccess.
Code:
new Thread(new Runnable() {
public void run()
{
int icon = R.drawable.icon;
long when = System.currentTimeMillis();
while(true)
{
android.os.SystemClock.sleep(60000);
managerActivity.notification = new Notification(icon, "", when);
CharSequence contentTitle = "Task manager";
CharSequence contentText= "Click here to open Tablet popup manager";
if(MainPopup.taskNames!=null){
contentText = String.valueOf(MainPopup.numOfTasks)+ " Tasks";}
managerActivity.notification.flags |= Notification.FLAG_NO_CLEAR;
if(managerActivity.notification!=null)
{
managerActivity.notification.setLatestEventInfo(getApplicationContext(), contentTitle, contentText, contentIntent);
mNotificationManager.notify(1,managerActivity.notification);
}
}
}
}).start();
please someone ?!
I really need this help

Categories

Resources