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);
Related
I am trying to open the settings page using intent for peripheral devices in tablet .
But i am finding no parameters in action_settings.
Please help me . your help will be much appreciated
That would appear to be a custom change to the Settings app made by that manufacturer. The manufacturer might be able to suggest an Intent that leads to that particular screen. However, you will not find a documented Intent action in the Android SDK for it, as it is not a standard Settings screen.
If you wanted to try an undocumented approach, you could check Logcat and see what entries are logged when you click the Settings item to open that screen. Activity starts get logged with some Intent details, and you may be able to reverse-engineer the Intent that your app can use that way.
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.
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.).
I am new to android. I am making an application for reading the pdf files. For this i want to integrate some existing open source apk with my application. Please suggest and give me example, how i can bind the apk with my application and how to call the apk from within the application activity. I think there should be something used by intent but not sure. Also if there can be any code to develop our own pdf reader, please share. Thanks.
As i know, integrating an apk directly from another application is not possible. This can not be achieved unless you know the source code of the apk. If this is the case.
Now its like this if you want to invoke Application2 from Application1 then you have to add one more intent filter in the Application2, you have to define an action in Application2 Manifest like
<action android:name="com.app2.intent.action.INVOKE_APP2"/>
and then define intent in your Application1 as
Intent i=new Intent("com.app2.intent.action.INVOKE_APP2");
startActivity(i);
It only possible if you know exactly what kind of intent (Action, data, type) the activities in that apk would be able to react.
You can use either startActivity(intent) or startActivityForResult(intent) once you know what the intent should be like.
An APK is not source code. You cannot directly interact with it if it was not meant to allow this, through intents. If you're starting on Android, I suggest you take some time familiarizing yourself with intents and intent-filters, they're one of the "unique" aspects of Android development, and you can do quite powerful things when you know what you're doing.
http://developer.android.com/reference/android/content/Intent.html
But please note in order to do that, you need to have the user install both apps (the original apk and yours). As far as I know, there is no way to "embed" an apk within your own app.
Also, please have a look at that question and this one, they overlap a little bit what you're asking.
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.