Launch Google Maps from app - java

I have setup my app to launch Google maps to a set location using the code below, but the map displays zoomed full and you cant see any roads you have to zoom out manually to see anything. How can I set the zoom level with the code below I've tried setZoom(16); but this has no effect.
if (mapnav == 10) {
String uri = "geo: 53.777969,-1.571474";
setZoom(16);
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(i);}
Also can I launch into Directions instead of the map

You can specify a zoom level in your URI with for example "geo: 53.777969,-1.571474?z=23"
Google Maps
geo:latitude,longitude
geo:latitude,longitude?z=zoom
geo:0,0?q=my+street+address
geo:0,0?q=business+near+city
VIEW
Opens the Maps application to the given location or query. The Geo URI scheme (not fully supported) is currently under development.
The z field specifies the zoom level. A zoom level of 1 shows the whole Earth, centered at the given lat,lng. A zoom level of 2 shows a quarter of the Earth, and so on. The highest zoom level is 23. A larger zoom level will be clamped to 23.
For the google navigation part you can use "google.navigation:q="+location where location are the coordinates. The intent Intent.ACTION_VIEW.
Resources :
developer.android.com - Intents List: Invoking Google Applications on Android Devices
On the same topic :
Google Navigation (Android 1.6) intent callback

Related

Automatically/Programmaticaly tap foreground service window that is always on top

I have challenged myself to code an in house app similar to Google's assistant voice tapping app. Everything is finished except the auto tap feature. When I launch the app it spins up a foreground service that draws a 8x8 grid that is always on top. Even when the main activity is minimized. The service uses an imageview that is set drawable. I then wrote an algorithm that draws a grid within it numbered 1 through 64. The user says which number to tap and the service does just that but nothing happens. I Log.wtf the tap coordinates x,y and it works perfectly when my main activity is open. when minimized it doesnt log the event OR its taping the wrong view.
Any suggestions?
Here is the code inside my custom window class that pops the window and sets the tap transperency so that taps pass through to the target app behind it. tPars is different for testing purposes. Both are window parameters.
`
mPars=new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
PixelFormat.TRANSLUCENT);
lInflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
gridView = lInflater.inflate(R.layout.window_overlay,null);
iv = gridView.findViewById(R.id.iv);
ivHolder= gridView.findViewById(R.id.ivHolder);
((ImageView)iv).setImageDrawable(new Draw());
mPars.gravity=Gravity.CENTER;
mWManager=(WindowManager) context.getSystemService(WINDOW_SERVICE);
`
Ive even tried using System.exec("Touch X,Y"). Still same issue. Broadcast receivers wont work as the goal is to stay within the service WHILE using other apps. Its an auto tap assistant app like googles.
I would like to utilize this ---> MOTION EVENT
To reiterate, Once Main Activity spins up the service I no longer want or need it as the user will be using other apps. My app allows them to Tap/Scroll with their voice via the foreground service overlay.
Thanks in advance.
I tried MotionEvent, System.exec, and a few 3rd party APIs. It will only tap withing Main Activities view.
EDIT
Here is my tap and recognition code.
else if(sentence.get(0).equalsIgnoreCase("tap")){
mWManager.addView(gridView, mPars);
grid.draw(new Canvas());
tap(548F,946F);
}
and execution
private void tap(Float x, Float y) {
gridView.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis()+100, (int)MotionEvent.ACTION_DOWN, x, y, 0));
gridView.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis()+100, (int)MotionEvent.ACTION_UP, x, y, 0));
}

Kivy Android Camera API 2 - Camera Rotation

I am using the camera feature defined in the following repo but with some changes. I just want to rotate the SurfaceTexture defined in camera2.py so that the camera can also work in portrait mode.
I tried Push- and Pop- Matrix solution but it shadows the buttons in the camera. Hence, I want it to be solved on the Java side rather than the Kivy side.
This is the link to the repo:
https://github.com/inclement/colour-blind-camera
This is where the main problem lies in:
https://github.com/inclement/colour-blind-camera/blob/master/camera2/camera2.py
I do not add the whole snippet here since it is too long but it is basically somewhere around the following snippet (Line 263):
self.preview_resolution = resolution
self._prepare_preview_fbo(resolution)
self.preview_texture = Texture(
width=resolution[0], height=resolution[1], target=GL_TEXTURE_EXTERNAL_OES, colorfmt="rgba")
logger.info("Texture id is {}".format(self.preview_texture.id))
self.java_preview_surface_texture = SurfaceTexture(int(self.preview_texture.id))
self.java_preview_surface_texture.setDefaultBufferSize(*resolution)
self.java_preview_surface = Surface(self.java_preview_surface_texture)
Any help appreciated a lot!

How to take a screen shot with status bar contents in android application?

I have a requirement that I have to take a screenshot of the current window in android.
This is the code am using,
View rootView = getWindow().getDecorView().findViewById(android.R.id.content);
View screenView = rootView.getRootView();
screenView.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(screenView.getDrawingCache());
screenView.setDrawingCacheEnabled(false);
by using this I could get the application screen shot, but the status bar contents are missing (bluetooth icon, battery status etc).
How can I take a screenshot of the current Android phone window programmatically (including status bar contents)?
Is it possible?
On Android 5.0+, use the media projection APIs to take a screenshot of the device screen. See this sample app, as the process is somewhat involved.
On older Android devices, there is no support for programmatic screenshots of the device screen.

launch two apps, Android nougat

I want to create an app for android nougat, when I click on a button I launch two apps at the same moment and the same screen.
I want to use this new feature of Android 7, Is it possible?
You can use Accessibility API for such feature. It doesn't require any permissions.
android.accessibilityservice.AccessibilityService has following apis:
service.performGlobalAction(GLOBAL_ACTION_TOGGLE_SPLIT_SCREEN) which you can use to initiate split screen mode.
public List<AccessibilityWindowInfo> getWindows () to check wether split screen mode is on. Look for a window with AccessibilityWindowInfo.TYPE_SPLIT_SCREEN_DIVIDER
You also will need to play with intent flags when launching activities.
val options = ActivityOptionsCompat.makeBasic().toBundle()?.apply {
putInt(
ActivityOptionsFlags.KEY_LAUNCH_WINDOWING_MODE,
ActivityOptionsFlags.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY
)
putInt(
ActivityOptionsFlags.KEY_SPLIT_SCREEN_CREATE_MODE,
ActivityOptionsFlags.SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT
)
}
startActivities(listOf(intentBottom, intentTop).toTypedArray(), options)
Using this accessibility apis and intent flags you can achieve your goal. Consult this repo by stavangr for detailed implementation.
https://developer.android.com/reference/android/accessibilityservice/AccessibilityService.html

Add custom View as marker in Google Maps API v2

I've developed a class that inherits from a View class and I want it to serve as a marker on a MapFragment/MapView from a Google Maps API v2. As I recall, such thing was possible in API v1 and even now it is possible on iOS. I'm looking for something like this:
MapView map = (MapView)findViewById(R.id.mapview);
CircleTimerView myTimer = new CircleTimerView(this);
LayoutParams lp = new LayoutParams(iv.getWidth(), iv.getHeight(), geoPoint, LayoutParams.BOTTOM);
map.addView(myTimer,lp);
My custom View is animated and it is a key feature of my app.
My question is: Is it possible for a current state of Google Maps API? Or should I try to obtain API v1 key and work with something that was deprecated?
Thanks in advance for your replies.
should I try to obtain API v1 key and work with something that was deprecated?
You cannot obtain new keys for API v1.
My custom View is animated and it is a key feature of my app.
You cannot have animated Marker icon unless you repeatedly change the icon using Marker.setIcon.
Is it possible for a current state of Google Maps API?
You can use a View as icon if you draw it into a Bitmap first.
This library from Chris Broadfoot can greatly help you with that task:
https://github.com/googlemaps/android-maps-utils
See this video for what the lib can do: http://www.youtube.com/watch?v=nb2X9IjjZpM
Or the new website: http://googlemaps.github.io/android-maps-utils/
in order to customize / use your own custom maker on google maps api v2 you could write the code as follows:
in onCreate declare the marker:
userIcon = R.drawable.red;
and then i used it where you need it, in my case i used it in a method:
if(userMarker!=null) userMarker.remove();
userMarker = theMap.addMarker(new MarkerOptions()
.position(lastLatLng)
.title("You are here")
.icon(BitmapDescriptorFactory.fromResource(userIcon))
.snippet("Your last recorded location"));
theMap.animateCamera(CameraUpdateFactory.newLatLng(lastLatLng), 100, null);
CameraUpdate center=
CameraUpdateFactory.newLatLng(lastLatLng);
CameraUpdate zoom=CameraUpdateFactory.zoomTo(15);
theMap.moveCamera(center);
theMap.animateCamera(zoom);
hope this helped. good luck
i had the same issue these days and you should do the switch for v2 as you can do all the same stuff from v1 easier + many new features.
MapView has been replaced with the new GoogleMap-Objecttype.
A very detailed and decent Tutorial site can be found HERE!

Categories