[英]Share application link and apk file in android
I Make a button for both apk and link share link share is working fine but when app will be share the apk name is changed to "untitled" i want the same name as my apk name 我为apk和链接共享都创建了一个按钮,链接共享工作正常,但是当要共享应用程序时,apk名称更改为“无标题”,我希望使用与我的apk名称相同的名称
my code for link 我的链接代码
btnShare.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ApplicationInfo app = getApplicationContext().getApplicationInfo();
String filePath = app.publicSourceDir;
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri uri = Uri.parse(filePath);
sharingIntent.setType("*/*");
sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
sharingIntent.putExtra(Intent.EXTRA_TEXT, "Click to blue link and download thegame. https://drive.google.com/open?id=10Nc5BoYn4NZ_O8ae32UVQwyzdCzFxNy");
startActivity(Intent.createChooser(sharingIntent, "Share app using"));
}
});
If you want to share your app link and your apk file, do it as separate task. 如果您想共享您的应用程序链接和apk文件, 请单独执行。 (with two buttons) (有两个按钮)
Sharing link can be done as you mentioned since it is a text. 由于它是文本,因此可以按照您提到的方式进行共享链接。
To share apk file,First you need to get your app apk file as, 要共享apk文件,首先, 您需要以以下方式获取您的应用apk文件 ,
ApplicationInfo packageinfo = context.getPackageManager().getApplicationInfo(yourpackagename, 0);
File file = new File(packageinfo.publicSourceDir);
Then copy the file to another one 然后将文件复制到另一个
try {
//Make new directory in new location
File tempFile = new File(getExternalCacheDir() + "/ExtractedApk");
//If directory doesn't exists create new
if (!tempFile.isDirectory())
if (!tempFile.mkdirs())
return;
//Get application's name and convert to lowercase
tempFile = new File(tempFile.getPath() + "/" + "appname" + ".apk");
//If file doesn't exists create new
if (!tempFile.exists()) {
if (!tempFile.createNewFile()) {
return;
}
}
//Copy file to new location
InputStream in = new FileInputStream(originalApk);
OutputStream out = new FileOutputStream(tempFile);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
System.out.println("File copied.");
//Open share dialog
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(tempFile));
startActivity(Intent.createChooser(intent, "Share app via"));
} catch (IOException e) {
e.printStackTrace();
}
You can share it using created file path 您可以使用创建的文件路径共享它
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri uri = Uri.parse(filepath);
sharingIntent.setType("*/*");
sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
sharingIntent.putExtra(Intent.EXTRA_TEXT, "Click to blue link and download thegame. https://drive.google.com/open?id=10Nc5BoYn4NZ_O8ae32UVQwyzdCzFxNy");
startActivity(Intent.createChooser(sharingIntent, "Share app using"));
This will change content as text/apk based on chosen application 这将根据所选应用程序将内容更改为文本/ apk
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.