After several tests, finally I can start an activity when an alert is
fired. I have used the example code from openintents.
To achieve start an activity I have add into AndroidManifest.xml :
<activity android:name="InformationClass" android:icon="@drawable/
icon" android:label="@string/app_name">
<intent-filter>
<action
android:name="net.mobilefight.trackbuilder.action.PROXIMITY_ALERT">
</action>
<category android:name="android.intent.category.DEFAULT">
</category>
</intent-filter>
</activity>
InformationClass is an activity. This activity is the one that I want
to fire when the proximity alert is fired. The code that I have used
into my Intent receiver class for start an activity is:
class ProximityIntentReceiver extends IntentReceiver
{
@Override
public void onReceiveIntent(Context context, Intent intent)
{
Intent i;
String action = intent.getAction();
if (action.equals(PROXIMITY_ALERT))
{
if (!alert_activated)
{
i = new Intent();
i.setAction(PROXIMITY_ALERT);
i.addCategory(Intent.DEFAULT_CATEGORY);
context.broadcastIntent(i);
int receiverCount =
context.getPackageManager().queryIntentReceivers(i, 0).size();
Log.i("TAG TRACKBUILDER : ", "receiver count:"
+ receiverCount);
if (receiverCount == 0){
int activityCount =
context.getPackageManager().queryIntentActivities(i, 0).size();
if (activityCount > 0)
{
alert_activated = true;
Log.w("TAG TRACKBUILDER : ",
"Activity found.");
i.setLaunchFlags(Intent.NEW_TASK_LAUNCH);
context.startActivity(i);
}
else
{
Log.w("TAG TRACKBUILDER : ",
"no activity found");
}
} else {
Log.i("TAG TRACKBUILDER : ", "broadcast
count:" +
receiverCount);
}
}
}
}
}
With this code I have a problem, only work correctly the first time. I
use a boolean variable to avoid that the activity be opened many times
because while the GPS point is into the radius of the alert, It is
fired and then a lot of applications are fired.
There is some way to disable the alert when application has been
launched and when exit from this application return to enable the
alert?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---