Android integrating apk with an application - java

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.

Related

How to make a phone call without switching activities to a default calling app in android?

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.

Reinstall application apk programmatically without downloading

Due to this annoying Android limitation I need users to reinstall my application so the manifest permissions are detected by other applications.
This is already going to be frustrating for the user, but in addition, I cannot see a way to reinstall my application from the apk stored in /data/app and I would therefore have to download the same version to the storage card before firing the usual install intent.
I eagerly await someone telling me that I'm missing something obvious! I've drawn a blank...
Thanks in advance.
Please do star the issue if you'd like to see it resolved! Cheers.
EDIT: With the comments of #hackbod in mind, you can use the following code to initiate the install dialog.
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(this.getApplicationInfo().sourceDir)),
"application/vnd.android.package-archive");
startActivity(intent);
On my Jelly Bean device, this presents two options: Package installer and Verify and install. I don't know if the latter will deal with the issue of:
Installing your app this way will probably remove ownership of it from the Play Store
My application is free, so I cannot test the paid issue of:
Note however if your app is forward locked (which is unavoidable for all paid applications starting with JB, due to the app encryption), then this won't work because your app executable is not readable by others
Although hackbod finishes with 'readable by others' which suggests that if you are executing this through your own code, for your own application, it is readable? Please do correct me if you can test this and I'm wrong.
Conceivably you could just get the path to your .apk through Context.getApplicationInfo().sourceDir, and launch the app installer with that path. Not however if your app is forward locked (which is unavoidable for all paid applications starting with JB, due to the app encryption), then this won't work because your app executable is not readable by others. In that case you would need to copy the .apk to somewhere world readable (such as in external storage) and install it from there.
No matter what you do here, though, this has some unavoidable very negative consequences:
The only way to do any kind of install from your app is to go through the side-loading UI, which is (a) going to be a very scary experience for the user, and (b) will require that the user turn on side-loading to be able to proceed.
Installing your app this way will probably remove ownership of it from the Play Store (since it is no longer the one that has installed it). This may mean for example that the user can no longer report crashes or ANRs to you through the play store, or other negative consequences. I am not sure exactly what problems will actually happen here, but I really wouldn't assume that this is going to be okay.
Ultimately, I just would very much not suggest doing this. What permission are you needing that is forcing you to do this? For many reasons, I wouldn't recommend that third party applications declare their own permissions in most cases, because there are a lot of bad user experiences around permissions that are only known after they may have been needed.

Include a service in a SDK/library

I've gotten an android service written as a stand-alone APK and I'm trying to include this in the SDK so it automatically installs the service through some publicly exposed function from the SDK.
Is there a way to achieve this?
For instance, the SDK is monitor.jar which has helper functions.
The service is GetCurrentMonitor.apk which runs a background service that returns the value of some stock currently monitoring.
Now, I want to release the SDK so that when it's included in some 3rd party app, it automagically installs the background service for GetCurrentMonitor project...
Any help is greatly appreciated.
Thank you,
Your question is very confusing. Here is my interpretation of what you are asking:
I have an Android application that has a service. I have a separate SDK (JAR or Android library project). I want users of the SDK to be able to call a function and have the APK containing the service be downloaded and installed.
This is possible, sorta.
You can have code in your JAR that either:
call startActivity() on an ACTION_VIEW Intent for the market: Uri pointing to your app on Google Play, or
downloads an APK from some server of yours to external storage, then calls startActivity() on an ACTION_VIEW Intent pointing to that downloaded APK, to kick off an install
In either case, the user will need to get involved in the installation process -- you cannot install apps silently. And, in the latter case, you will be responsible for handling your own updates over time.
This also will tend to confuse the user, as they may not realize why your app is floating around their device, so you will need to be able to handle the case where they uninstall it.
Also, it is possible that on Android 3.1+, the user will need to launch an activity of yours before your service will be usable. With luck, that is not required, though I cannot rule it out at this time.
And, of course, if I did not correctly understand your question, please consider editing the question to clarify what it is you are trying to accomplish.

Showing all broadcast events on Android

is it somehow possible to show all broadcast events/intents that are triggered in android? I just want to know if I can quickly figure out if an application is using intents/broadcasts I can hook into. For most of the stock android applications I can read the source but is time consuming.
List all historical broadcasts and registered broadcast receivers with the following terminal command:
$ adb shell dumpsys activity broadcasts
Please check this open source project to see all broadcasts on your android phone:Broadcasts Monitor Pro
There's logcat, which you can get to from the ddms (either the dedicated app, or the eclipse view), it should list all broadcasts, as well as the properties that are associated with the intent. However, as the other commenters on your post have stated, you really shouldn't be doing that unless the intent has been published. It may change, or cause other forms of havoc. Although I disagree with the statement, some people may even go so far as to say that it's illegal if the licenses aren't compatible. (Although I'm of the party that it's not, seeing as you're not statically linking to the code, nor even putting it in your package).
The best tool I found was Intent Intercept that catches the intent on the fly and allow you to inspect the content

Step/Debug Android built-in applications

I have downloaded the Android source code and can see the java source files for the built-in applications (e.g. com.android.contacts.ContactsListActivity). I am trying to discover how these applications re-use one another via Intents etc. I would also like to see how the UI layouts are assembled for these applications as a design for my own apps.
About using Intents and Intent Filters, if you are less experienced, it will be best for you, if you start learning from a book, then try something in your own application, and only after that dive in the pre-installed apps, IMHO.
You can debug built-in applications, just like any other application, if you have the source. If you want to install other version of a built-in app, you must use the appropriate Intent Filters and change the package name, so that it's different than the original application's.
If you are using the source code, browsing through the internal classes should be helpful, so take a look here.
If you want to examine the UI layout of the built-in apps, the hierarchyviewer in your Android /tools/ folder is your best choice (my second favorite of the bunch, after traceview).
Write back, if something is unclear or doesn't work for you.
Good luck.

Categories

Resources