Last active
November 9, 2018 09:08
-
-
Save s1ntoneli/7af015b9c7c8ae35970ceedfc62275ac to your computer and use it in GitHub Desktop.
分享应用自己的apk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<provider | |
android:name="androidx.core.content.FileProvider" | |
android:authorities="com.xxxx.fileprovider" | |
android:exported="false" | |
android:grantUriPermissions="true"> | |
<meta-data | |
android:name="android.support.FILE_PROVIDER_PATHS" | |
android:resource="@xml/file_paths" /> | |
</provider> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<paths xmlns:android="http://schemas.android.com/apk/res/android"> | |
<root-path | |
name="app" | |
path=""/> | |
</paths> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void shareApk(Context context) { | |
ApplicationInfo app = context.getApplicationInfo(); | |
String filePath = app.sourceDir; | |
Intent intent = new Intent(Intent.ACTION_SEND); | |
intent.setType("*/*"); | |
intent.setPackage("com.android.bluetooth"); | |
Uri uri = FileProvider.getUriForFile(context, "com.xxxx.fileprovider", new File(filePath)); | |
intent.putExtra(Intent.EXTRA_STREAM, uri); | |
// intent.setData(uri); | |
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); | |
// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
Intent chooser = Intent.createChooser(intent, "Share app"); | |
chooser.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
context.startActivity(chooser); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment