Skip to content

Commit

Permalink
Added map intent
Browse files Browse the repository at this point in the history
  • Loading branch information
robgruen committed Nov 4, 2024
1 parent 1431d79 commit ac116eb
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 17 deletions.
8 changes: 0 additions & 8 deletions android/samples/mobile/.idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions android/samples/mobile/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

<uses-feature android:name="android.hardware.camera.any" android:required="true" />
<uses-feature
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@ package com.microsoft.typeagent.sample

import android.content.Context
import android.content.Intent
import android.icu.util.Calendar
import android.net.Uri
import android.provider.AlarmClock
import android.webkit.JavascriptInterface
import android.widget.Toast
import androidx.compose.ui.platform.LocalContext
import androidx.core.content.ContextCompat.startActivity
import java.time.LocalDateTime
import java.util.Date
import java.util.Locale


Expand Down Expand Up @@ -53,4 +50,12 @@ class JavaScriptInterface(var context: Context) {
.putExtra("sms_body", message);
startActivity(context, intent, null)
}

@JavascriptInterface
fun searchNearby(searchTerm: String) {
val uri = Uri.parse("geo:0,0?q=$searchTerm")
val intent = Intent(Intent.ACTION_VIEW, uri)
intent.setPackage("com.google.android.apps.maps")
startActivity(context, intent, null)
}
}
3 changes: 2 additions & 1 deletion ts/packages/agentSdk/src/display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export type ClientAction =
| "show-notification"
| "set-alarm"
| "call-phonenumber"
| "send-sms";
| "send-sms"
| "search-nearby";

export interface ActionIO {
readonly type: DisplayType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
ActionResult,
} from "@typeagent/agent-sdk";
import { createActionResult } from "@typeagent/agent-sdk/helpers/action";
import { AndroidMobileAction, CallPhoneNumberAction, SendSMSAction, SetAlarmAction } from "./androidMobileSchema.js";
import { AndroidMobileAction, CallPhoneNumberAction, SearchNearbyAction, SendSMSAction, SetAlarmAction } from "./androidMobileSchema.js";

export function instantiate(): AppAgent {
return {
Expand Down Expand Up @@ -72,6 +72,12 @@ async function handlePhotoAction(
context.actionIO.takeAction("set-alarm", alarmAction.parameters);
break;
}
case "searchNearby": {
let nearbySearchAction = action as SearchNearbyAction;
result = createActionResult("Local search");
context.actionIO.takeAction("search-nearby", nearbySearchAction.parameters);
break;
}
default:
throw new Error(`Unknown action: ${action}`);
}
Expand Down
14 changes: 12 additions & 2 deletions ts/packages/agents/androidMobile/src/androidMobileSchema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

export type AndroidMobileAction = SendSMSAction | CallPhoneNumberAction | SetAlarmAction;
export type AndroidMobileAction = SendSMSAction | CallPhoneNumberAction | SetAlarmAction | SearchNearbyAction;

// sends a SMS to the supplied phone number
export type SendSMSAction = {
Expand Down Expand Up @@ -36,4 +36,14 @@ export type SetAlarmAction = {
// the time for the alarm in the format YYYY-mm-ddThh:mm:ss (i.e. 2024-02-15T08:30:15 )
time: string;
};
};
};

export type SearchNearbyAction = {
actionName: "searchNearby";
parameters: {
// the original request of the user
originalRequest: string;
// the search term to use when searching nearby locations
searchTerm: string;
};
}
1 change: 1 addition & 0 deletions ts/packages/shell/src/lib/lib.android.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ declare var Android: {
setAlarm: (time: string) => void;
callPhoneNumber: (phoneNumber: string) => void;
sendSMS: (phoneNumber: string, message: string) => void;
searchNearby: (searchTerm: string) => void;
};
7 changes: 5 additions & 2 deletions ts/packages/shell/src/renderer/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ function addEvents(
api.onTakeAction((_, action: string, data?: unknown) => {
// Android object gets injected on Android devices, otherwise unavailable
try {
//Android?.showToast("woohooo 2!");
console.log(`Take Action '${action}' Data: ${data}`);
switch (action) {
case "show-camera": {
Expand All @@ -224,7 +223,11 @@ function addEvents(
}
case "send-sms": {
let d: any = data;
Android.sendSMS(d.phoneNumber, d.message);
Android?.sendSMS(d.phoneNumber, d.message);
}
case "search-nearby": {
let d: any = data;
Android?.searchNearby(d.searchTerm);
}
}
} catch (e) {
Expand Down

0 comments on commit ac116eb

Please sign in to comment.