For context, I'm trying to create an Android app in Java that can share itself to other phones. I managed to get the app to successfully send its own APK to another android phone using bluetooth (see implementation below).
The problem is that the APK from one phone will not install on another phone. To troubleshoot, I downloaded a third-party APK extractor to send my app across with the same results - the APK is successfully transferred but won't install on the other phone. I then tried to use the APK extractor to share a random selection of Google Play apps, some apps would successfully install on the second phone, others wouldn't.
At this stage, I'm quiet sure this is a compatibility issue. How could I make my APK be more compatible across devices? For reference, I'm currently testing it on 3 phones: Samsung Galaxy S7, Huawei Nova 3i and Motorolla XT1052, but ultimately I want the app to be accessible on as many devices as possible.
Thanks in advance :)
sendApp Function
public void sendApp(Activity activity) {
try {
PackageManager pm = activity.getPackageManager();
ApplicationInfo app = pm.getApplicationInfo(activity.getPackageName(), 0);
File apkFile = new File(app.publicSourceDir);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("*/*");
Uri uri = FileProvider.getUriForFile(
getApplicationContext(),
BuildConfig.APPLICATION_ID + ".provider", //(use your app signature + ".provider" )
apkFile);
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
}
Manifest.xml Provider Tag:
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<!-- resource file to create -->
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths">
</meta-data>
</provider>
file_paths.xml
<?xml version="1.0" encoding="utf-8"?>
<paths>
<root-path
name="root"
path="."/>
</paths>
Found out the problem! I was sending across the debug APK, not the release APK. I just created a signed APK in Android studio (Build>Generate Signed Bundle/APK). I didn't come up with the solution myself, however the answerer removed their answer before I could select it.