Is there a way to set an address in an application so when it is clicked it automatically opens it in Google Maps? I may end up implementing Maps into my application but it is a simple reference app simply to find the address.
You do this via an Intent.
The various URI formats you can use are:
geo:latitude,longitude
geo:latitude,longitude?z=zoom
geo:0,0?q=my+street+address
geo:0,0?q=business+near+city
See http://developer.android.com/guide/appendix/g-app-intents.html for more details.
You build the URI, and pass it to the intent, like this.
String uri = "geo:latitude,longitude";
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
You might also want to make sure that the Google Maps application is actually installed on the device, described here, so you don't run afoul of devices that don't have Google Maps installed (Amazon Kindle, Barnes & Noble Nook, etc.).
Related
I'm trying to make a phone call from my app in a way it does not need to switch activities, But every guide I find has the following code snippet,
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:XXXXXXXXX"));
startActivity(callIntent);
which switches the activity I start the call from to another activity (in this case to an activity in a different app). Is there a way to stop this from happening? I managed to do it with a third party library called "sinch" but I'm wondering if there is a native way to do it or maybe a better library?
Ps- the app I'm building it for myself, basically, I'm building a voice assistant that can make calls via voice commands, hence I can't let it switch activities. I have no intention of publishing it on the app store and I have no difficulty giving dangerous permissions :) My plan is to run it on a separate piece of hardware in the future.
This link can help you, but as Xavier Rubio Jansana wrote previously, Google hardly accepts applications that do not use intents to make phone calls :
https://google-developer-training.github.io/android-developer-phone-sms-course/Lesson%201/1_c_phone_calls.html
Google wants any programmer to use an intent to make the user view the default phone application handle the phone call.
If your app does not need to be available on Google Play Store then it would be ok for you to make the phone call directly.
To elaborate on what I was talking about earlier, it is talked about in this stack overflow question (perhaps upvote their answers if they are helpful). How to make a phone call using intent in Android?.
From memory, ACTION_DIAL will bring up the dialler and pre-populate the number.. it requires no special permission because it requires the user to actually place the call.
On the other hand, ACTION_CALL will actually initiate the call and requires special permissions.
If returning focus (bringing your app back to the foreground) is a concern, you could try using a scheduled intent to (re) launch your activity (maybe using alarm manager or similar) some time after invoking the dialler. You can retain state with a little care around launch modes in the intent and/or a special "do nothing" activity published in your app manifest which does nothing but re-activate your app.
I have an android app that the features may keep updating from time to time. Those features are hard coded into the app and I feel that if like 100 users download the app and when some features of the app is updated and re-upload to the play store those users who have installed the app prior now may have lost out on some of the latest features uploaded to the play store.
To tackle this issue I arrived at this solution as described in the url but yet to implement it in the onCreate method
Intent intent = new Intent(Intent.ACTION_VIEW ,Uri.parse("market://details?id=com.package.name"));
startActivity(intent);
Is there a way to automatically update application on Android?
I want to be guided properly please, if this approach will solve my doubts. Kindly assist!
if you used web serivce then pass your app version to web team.
and then getting first web service call one flag for app is old or not
and you can manullay set dialog when app is open. and then redirect appp to playsotre.
The solution you are looking for is REACT NATIVE APPS.
React Native apps allows you to change and add many features without uploading the app to play store.
https://facebook.github.io/react-native/showcase.html
UPDATE
But If you want to use android native development then.
Make an API in your backend which will return the latest version of your app in its response like:
{
appVersion: "4.2.1"
}
Then in your android app on the first activity make a call to this API and compare the version of your application with the API version.
String currentVersion = BuildConfig.VERSION_NAME;
If it doesn't match then show a message to the user to update the app from play store and give a button which will redirect to your app link on google play store.
Whenever you update your app in play store change the version in your API.
You can also maintain versions for major and minor update.
{
majorVersion:4
minorVersion:1
patchVersion:2
}
Then in your app:
String majorVersion = android.optString("majorVersion");
String minorVersion = android.optString("minorVersion");
String patchVersion = android.optString("patchVersion");
String[] ab = BuildConfig.VERSION_NAME.split("\\.", 3);
String appMajorVersion = ab[0];
String appMinorVersion = ab[1];
And use if else to check whether you need to force update or not.
I'm developing an app using Ionic Framework. Within this app I have some geo uri encoded location links. In the upcoming Android-system option dialog where to choose an appropriate app to handle this intent it provides the following apps: Google Maps and Earth. As I have also OsmAnd installed it should also provide this as an option. Using 'geo:uri' intents from a native Android app does provide this option.
Does anyone has a clue why that happens and how to get this option?
Added
Within the ionic app I have this link:
Show
Angular is configured with:
$compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|geo):/);
This is what it looks like (my app using geo uri) and what it should look like (wiki entry with geo uri):
I have a custom launcher and at times want to add a button to launch third party applications. To do this I need the apps package name, which is easy to find, but also the apps main or starting activity. I use this to create Intents that I pass to my app.
For example, to create an intent that launches Skype I use:
`new Intent().setComponent(new ComponentName("com.skype.raider", "com.skype.raider.Main"))
I was able to find the name of the main activity by Googling around and as Skype is a popular app it showed up eventually.
I know that if I have the APK I can just open it and look at the androidmainifest , however I'm not sure how to get the APK's of some apps at all. For instance, I want to start this app from Google Play . I can see the package name, com.dbapp.android.mediahouse, however I'm not sure how to get the name of the main activity(I tried .MAIN).
I've looked at the Chrome extension apk downloader that supposendly allowed you to get APK's from Google Play but it appears to no longer work.
I know starting third party apps from a custom launcher is something that must be fairly common, but I'm not finding the answer when I search.
How do people typically handle this issue? Do you get the APK from the Google Play Store and if so how does one do that? Again, I know that I can get the activity from reading the manifest but I don't know how to get the APK itself in many cases. Any advice would be very much appreciated, thanks!
A launcher should be finding the MAIN/LAUNCHER activities advertised by apps on the device, by using PackageManager and queryIntentActivities(). Here is a sample app that implements such a launcher.
PackageManager pm=getPackageManager();
Intent main=new Intent(Intent.ACTION_MAIN, null);
main.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> launchables=pm.queryIntentActivities(main, 0);
You then use that List<ResolveInfo> to display the available activities in a ListView, GridView, etc.
The PackageManager offers a method to get exactly what you want:
PackageManager.getLaunchIntentForPackage(String packageName)
You can use Intent intent = new Intent(android.content.Intent.MAIN);
or like the example behind to launch Maps and parse a URI:
String uri = "http://maps.google.com/maps?saddr=" + Utils.getLatitude(ShowDetails.this)+","+Utils.getLongitude(ShowDetails.this)+"&daddr="+userLatitude+","+userLongitude;
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
I'm looking for a way to control the default Android media player from my own service. I'm NOT interested in playing media from my service or activity; I want to control the existing application, which consists of an activity (MediaPlaybackActivity.java) and more importantly a service (MediaPlaybackService.java) located in packages/apps/Music/src/com/android/music/. Ideally, I would like a solution that is independent of the version of Android.
I have figured out how to do pause/play/stop/next/previous operations using Intents. I can intercept track change events using a broadcast receiver. I can also get a list of playlists and the contents of each playlist. What I would like to be able to do is instruct the MediaPlaybackService to play a specific file/song. Again, I don't want to play this song in my application; I want the Android default media player to play it.
I have tried two approaches so far:
I imported the IMediaPlaybackService.aidl file from packages/apps/Music/src/com/android/music into my own application, and used this to bind to the MediaPlaybackService. On Froyo, this works great; I can pass a path to the openFile method, and the service will play the file. However, on Gingerbread, I get an error: Permission Denial: Accessing service ComponentInfo{com.google.android.music/com.android.music.MediaPlaybackService} from
pid=17721, uid=10058 requires null. Finding a workaround to this error would be a good temporary solution, but it's not future-proof. This service may well change again in future versions of Android.
Starting the media player via an ACTION_VIEW Intent. This also works; however, as expected, the media player UI is brought to the front, which is not ideal.
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(someUri, "audio/mp3");
startActivity(intent);
Is there any other way to accomplish this? Is there an Intent I missed that would instruct the media player to play a specific song? Or alternatively, is there away to start an activity in the background, or to start an activity and immediately switch back to the previous one?
Sorry, there is no supported way to do this. All of the stuff you are describing is using private implementation details, and as you have seen is not robust. If you want to play music, you should do it in your own app.
I'm looking for a way to control the default Android media player from my own service.
There is no "default Android media player". The application you are referring to may exist on some devices and will not exist on others. AFAICT, few devices will have what you think is the "default Android media player" going forward -- those not already running proprietary media players from device manufacturers may have the new proprietary Google Music app.