Recieveing a notification when an activity is launched

by Mark Murphy » Thu, 01 Jul 2010 14:57:34 GMT


Sponsored Links
 On Wed, Jun 30, 2010 at 5:31 AM, Christoffer Davidsson



No, sorry.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://github.com/commonsguy 
 http://commonsware.com/blog  |  http://twitter.com/commonsguy 

Android Training...At Your Office:  http://commonsware.com/training 

--



Recieveing a notification when an activity is launched

by TreKing » Fri, 02 Jul 2010 23:15:44 GMT


 On Wed, Jun 30, 2010 at 4:31 AM, Christoffer Davidsson <




Launched, no, as Mark said. But there should be broadcasts for install /
uninstall.

-------------------------------------------------------------------------------------------------
TreKing - Chicago transit tracking app for Android-powered devices
 http://sites.google.com/site/rezmobileapps/treking 

--


Sponsored Links


Other Threads

1. Sample.XML Layout examples equivalents of Style Constants

If we need to define our own Theme for example, but would like to
closelly follow an already existing theme, it would be very usefull,
to be able to access example Layouts, with content equivalent to the
current Style constant definitions, like defined in
http://code.google.com/android/reference/android/R.style.html#Theme

If thexe example.xml layout files were available, it would be easy to
setup a cloned xml file, with just the right tweeks that we need.

Besides this, it would also be a valid documentation by example,
because currently, I just can't find, how to disable the status bar,
inside a mytheme.xml.

However, there are at least two constants to define this, such a
Theme:
  public static final int Theme_NoTitleBar
  public static final int Theme_Light_NoTitleBar

This is fine, if we are pleased with all the other default settings
that these Themes force on us.
If we want to make something, different, Like Bordeux Color Background
(simple example only) but without status bar, we don't know what to
include inside our myTheme.xml file to accomplish something like this.

Hope there are some Undocumented Layout options to accomplish this,
and not only a constant that translates into some code internally,
that sets things up before our application activities are called..

--~--~---------~--~----~------------~-------~--~----~

2. About Xmppdataservicesender and Xmppdataservicereceiver in Android sample

Hi



    Can anybody please tell me  the reason of the error


Here the code is:



package com.Iw.Testapp1;

import android.app.Activity;
import android.os.Bundle;
import android.os.Bundle;
import android.os.IBinder;
import android.os.DeadObjectException;
import android.widget.Button;
import android.widget.EditText;
import android.content.ServiceConnection;
import android.content.ComponentName;
import android.content.Intent;
import android.content.Context;
import android.app.NotificationManager;
import android.app.Activity;
import android.view.View;
import android.text.TextUtils;
import android.util.Log;

import com.google.android.xmppService.IXmppService;
import com.google.android.xmppService.IXmppSession;

// Need the following import to get access to the app resources, since this
// class is in a sub-package.

public class Testapp1 extends Activity {

 /*
  * Copyright (C) 2007 Google Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *      http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */





 /**
  * <p>Example of using the
[EMAIL PROTECTED] to
  * receive peer to peer data messages.
  * This demonstrates how to use the XmppService to receive data to/from
another Android device.</p>

 <h4>Demo</h4>
 App/Service/Xmpp Data Message Receiver

 <h4>Source files</h4>
 <table class="LinkTable">
         <tr>
          <td
class="LinkColumn">src/com/google/android/samples/app/XmppDataMessageSender.java</td>
          <td class="DescrColumn">The XmppService data message Sender</td>
         </tr>
         <tr>
             <td
class="LinkColumn">src/com/google/android/samples/app/XmppDataMessageReceiver.java</td>
             <td class="DescrColumn">The XmppService data message
receiver</td>
         </tr>
         <tr>
             <td
class="LinkColumn">res/layout/xmpp_data_message_sender.xml</td>
             <td class="DescrColumn">Defines contents of the screen for the
Xmpp message sender</td>
         </tr>
 </table>

  */

     private static final String LOG_TAG = "XmppSrvSample";

     IXmppSession mXmppSession = null;
     EditText mUsernameField;
     Button mSendButton;

     @Override
     protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);

         Log.i("","create");
         setContentView(R.layout.xmpp_data_message_sender);
         mUsernameField = (EditText)findViewById(R.id.username);
         mUsernameField.setOnClickListener(mOnClickListener);
         mUsernameField.requestFocus();

         mSendButton = (Button)findViewById(R.id.send);
         mSendButton.setOnClickListener(mOnClickListener);
         mSendButton.setEnabled(false);

         bindXmppService();
         setContentView(R.layout.xmpp_data_message_sender);
     }

     @Override
     protected void onDestroy() {
         super.onDestroy();
         unbindService(mConnection);
     }

     private void bindXmppService() {
      Log.i("","bindXmppService");
         bindService((new Intent()).setComponent(

com.google.android.xmppService.XmppConstants.XMPP_SERVICE_COMPONENT),
                 null, mConnection, 0);
     }

     private boolean isValidUsername(String username) {
      Log.i("","valid username");
         if (TextUtils.isEmpty(username)) {
             return false;
         }

         if (username.indexOf('@') == -1) {
             return false;
         }

         return true;
     }


     private Intent getIntentToSend() {
      Log.i("","getIntentToSend");
         Intent intent = new Intent(XmppDataMessageReceiver.ACTION);
         intent.putExtra("poke", "Hi, I am Sam.");
         intent.putExtra("question", "would you like to eat green eggs and
ham?");

         return intent;
     }

     private void showMessage(CharSequence msg) {
      Log.i("","showMessage");
         NotificationManager nm = (NotificationManager)getSystemService(
                 Context.NOTIFICATION_SERVICE);

         nm.notifyWithText(123, msg,  NotificationManager.LENGTH_LONG,
null);
     }

     private ServiceConnection mConnection = new ServiceConnection() {

         public void onServiceConnected(ComponentName className, IBinder
service) {
             // This is called when the connection with the XmppService has
been
             // established, giving us the service object we can use to
             // interact with the service.  We are communicating with our
             // service through an IDL interface, so get a client-side
             // representation of that from the raw service object.
          Log.i("","onServiceConnected");
             IXmppService xmppService =
IXmppService.Stub.asInterface(service);

             try {
                 mXmppSession = xmppService.getDefaultSession();

                 if (mXmppSession == null) {
                     // this should not happen.
                     showMessage(getText(R.string.xmpp_session_not_found));
                     return;
                 }
             } catch (DeadObjectException ex) {
                 Log.e(LOG_TAG, "caught " + ex);
                 showMessage(getText(R.string.found_stale_xmpp_service));
             }

             mSendButton.setEnabled(true);
         }

         public void onServiceDisconnected(ComponentName className) {
             // This is called when the connection with the service has been
             // unexpectedly disconnected -- that is, its process crashed.
             mXmppSession = null;
             mSendButton.setEnabled(false);
         }
     };

     private View.OnClickListener mOnClickListener = new
View.OnClickListener() {

         public void onClick(View v) {
          Log.i("","OnClickr");
             if (v == mUsernameField) {
                 mSendButton.requestFocus();
             } else {
                 // use XmppService to send data message to someone
                 String username = mUsernameField.getText().toString();
                 if (!isValidUsername(username)) {
                     showMessage(getText(R.string.invalid_username));
                     return;
                 }

                 if (mXmppSession == null) {

showMessage(getText(R.string.xmpp_service_not_connected));
                     return;
                 }

                 try {
                     mXmppSession.sendDataMessage(username,
getIntentToSend());
                 } catch (DeadObjectException ex) {
                     Log.e(LOG_TAG, "caught " + ex);

showMessage(getText(R.string.found_stale_xmpp_service));
                     mXmppSession = null;
                     bindXmppService();
                 }
             }
         }
     };

 }


*
XmppDataMessageReceiver.java*

package com.Iw.Testapp1;

import android.app.Activity;
import android.os.Bundle;

import android.content.IntentReceiver;
import android.content.Context;
import android.content.Intent;
import android.app.NotificationManager;
import android.util.Log;
import android.os.Bundle;

import java.util.Map;
import java.util.Iterator;

public class XmppDataMessageReceiver extends Activity {

 /*
  * Copyright (C) 2007 Google Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *      http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */


 /**
  * <p>Example of using the
[EMAIL PROTECTED] to
  * receive peer to peer data messages.
  * This demonstrates how to use the XmppService to receive data to/from
another Android device.</p>

 <h4>Demo</h4>
 App/Service/Xmpp Data Message Receiver

 <h4>Source files</h4>
 <table class="LinkTable">
         <tr>
             <td
class="LinkColumn">src/com/google/android/samples/app/XmppDataMessageReceiver.java</td>
             <td class="DescrColumn">The XmppService data message
receiver</td>
         </tr>
         <tr>
             <td
class="LinkColumn">src/com/google/android/samples/app/XmppDataMessageSender.java</td>
             <td class="DescrColumn">The XmppService data message
Sender</td>
         </tr>
 </table>

  */

     private static final String LOG_TAG = "XmppSrvSample";

     /* package */ static final String ACTION =

"com.google.android.samples.app.XmppDataMessageReceiver.ACTION_DATA_MESSAGE";

     public void onReceiveIntent(Context context, Intent intent) {
         if (intent.getAction().equals(ACTION)) {
             StringBuilder buf = new StringBuilder();
             buf.append("Got data message, action=");
             buf.append(ACTION);

             Bundle bundle = intent.getExtras();
             if (bundle != null) {

                 if (bundle.getString("poke") != null) {
                     appendData(buf, "poke", bundle.getString("poke"));
                 }

                 if (bundle.getString("question") != null) {
                     appendData(buf, "question",
bundle.getString("question"));
                 }
             }

             Log.i(LOG_TAG, "[XmppDataMessageReceiver] onReceiveIntent: " +
buf);


             NotificationManager nm =
(NotificationManager)context.getSystemService(
                     Context.NOTIFICATION_SERVICE);

             nm.notifyWithText(123, buf.toString(),
                     NotificationManager.LENGTH_LONG, null);

         }
     }

     private void appendData(StringBuilder buf, String key, String value) {
         buf.append(", ");
         buf.append(key);
         buf.append('=');
         buf.append(value);
     }

 }

    *

xmpp_data_message_sender.xml

*

<AbsoluteLayout

id="@+id/outerborder"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

xmlns:android="http://schemas.android.com/apk/res/android">











<FrameLayout

id="@+id/edittext"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:layout_x="100.0sp"

android:layout_y="170.0sp"


<EditText id ="@+id/username"

android:text=" "

android:layout_width="75.0sp"

android:layout_height="wrap_content"

/>

</FrameLayout>

 <FrameLayout

id="@+id/textviews"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:layout_x="100.0sp"

android:layout_y="250.0sp"


<Button id ="@+id/send"

android:text="Label"

android:layout_width="100.0sp"

android:layout_height="20.0sp"

/>

</FrameLayout>

      </AbsoluteLayout >

Thanks
judy

--~--~---------~--~----~------------~-------~--~----~

3. MapView invalidate (is invalidating?)

4. Can Android app's contain only intent receivers?

5. Problem woth OnLongClickListener

6. Installing apk on the emulator

7. enquiry about the resubmission