Ameba Ownd

アプリで簡単、無料ホームページ作成

Janis Anderson's Ownd

Android download apk programmatically

2021.12.19 11:09






















You can go to this link: FileProvider. Allows an application to request installing packages. Apps targeting APIs greater than 25 must hold this permission in order to use Intent. In Android Oreo and above version we have to approach different methods to install apk programatically. In Oreo and above version we need unknown resource installation permission. Another solution that doesn't not require to hard-code the receiving app and that is therefore safer:.


Yes it's possible. But for that you need the phone to install unverified sources. For example, slideMe does that. I think the best thing you can do is to check if the application is present and send an intent for the Android Market. I don't know exactly how to start the activity but if you start an activity with that kind of url. It should open the android market and give you the choice to install the apps.


It's worth noting that if you use the DownloadManager to kick off your download, be sure to save it to an external location e. The intent with a package-archive type doesn't appear to like the content: scheme used with downloads to an internal location, but does like file:.


Trying to wrap the internal path into a File object and then getting the path doesn't work either, even though it results in a file: url, as the app won't parse the apk; looks like it must be external. Just an extension, if anyone need a library then this might help.


Thanks to Raghav. Came at this some two months ago and supposedly figured it out. Came back today and couldn't make heads or tails of it. Nothing had changed in my setup as far as I am aware, so apparently whatever past me had come up with wasn't robust enough for present me.


I finally managed to get something working again, so documenting it here for future me and anyone else who might stand to benefit from yet another attempt. It could probably use some additional work, but it's at least a start. I have it running on an Android 9 device, though I have the project targetting Android What I particularly like about this approach is that it does not require any special work in the manifest - no broadcast receivers, file providers, etc.


Granted, this takes as its source some APK in the app's assets, whereas a more useful system will probably use some given APK path. I imagine that will introduce a certain level of additional complexity.


In addition, I never ran into any issues here at least as far as I could tell with the Xamarin GC closing streams before Android was done with them. Nor did I have any issues with the APK not being parsed. I made sure to use a signed APK the one generated by Visual Studio when deploying to the device worked just fine , and again I did not run into any file access permission issues simply due to using an APK from the app's assets in this example.


One thing that some of the other answers here provided was the idea of making the sideloading permission grant more streamlined. The answer by Yabaze Cool provided this feature:. When I tested my translation, I uninstalled both the launcher demo and the app it installed. So adding this logic can help to somewhat simplify the installation process for the user.


Currently the API is in Beta state, but you can already do some tests yourself. Beside that, UpdateNode offers also displaying messages though the system - pretty useful if you want to tell something important to your users. I am part of the client dev team and am using at least the message functionality for my own Android App. See here a description how to integrate the API. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams?


Collectives on Stack Overflow. Learn more. Install Application programmatically on Android Ask Question. Asked 10 years, 10 months ago. Active 24 days ago. Viewed k times. Improve this question. Googlian 4, 3 3 gold badges 32 32 silver badges 33 33 bronze badges. What to do for this error? If you are getting this error, means you should cross check the package name and APK name of the app file. And one more thing I would like to ask.


APK is getting download in your device or not? I allowed Installation from Unknown Source as well. And, file is not getting downloaded. Thank you for sharing this. I have it implemented and working.


Thanks a lot. Hi, I checked this but its not working in my case.. Your email address will not be published. If you are new to android then go through with the video tutorial link attached Download and install app programmatically Here, I am letting you know few basic steps for doing this in very pure manner.


FileProvider ;. Activity; import android. ProgressDialog; import android. Context; import android. Intent; import android. PackageManager; import android. ResolveInfo; import android. Uri; import android. AsyncTask; import android. Build; import android. Bundle; import android.


Log; import android. View; import android. Button; import android. Toast; import androidx. NonNull; import androidx. RequiresApi; import androidx. AppCompatActivity; import androidx. ActivityCompat; import androidx. ContextCompat; import androidx. FileProvider; import java. File; import java. FileOutputStream; import java. I encountered a number of problems with old solution.


A lot of things have changed in that time, so I had to do this with a different approach. Here is the code:. I hope you appreciate it! Thanks for your code and solution. So I was thinking the solution was simply delete the APK on the sdcard, but them the Async task wil simply retrieve ver2 again for the server. So the only way to stop in from trying to install the v2 apk again is to remove from sdcard and from remote server.


As you can imagine that is not really going to work since I will never know when all users have received the lastest version. You need to name your APK file file some sort of versioning, remembering to always set your NEXT release version in your currently released app. Not ideal but functional. Stack Overflow for Teams — Collaborate and share knowledge with a private group.


Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Android: install. Asked 10 years, 9 months ago. Active 1 year, 8 months ago. Viewed k times. Improve this question. I assume that after the install, the apk is still in that download directory. How do you detect that the install was successful and delete the apk so it doesn't waste space? I used this method in my application, with the change below.


It works fine on 2. However, on 4. What am I missing? It only worked for me when I removed c. See stackoverflow. Show 3 more comments. Active Oldest Votes. Below show what I tried.. If you want install application programmatically in Android 10, You need to give permission to install app for your application. First, your Uri is invalid on every version of Android, outside of a few devices where the device manufacturer hacked in something for you.


Second, by default, neither you nor the package installer process have access to external storage on Android The solution for Android 10 and higher — which also works on Android 5. This sample app demonstrates how to use it. The key pieces are in MainMotor :. Inside of a coroutine, I create a PackageInstaller session, open the session, copy the APK contents to a session-supplied stream, then commit and close the session.


Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. How to install any Android app programmatically in Android 10 Ask Question.


Asked 1 year, 11 months ago. Active 1 year, 2 months ago.