Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/188.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在android中共享应用程序链接和apk文件_Android_Android Intent_Share Button_Explicit Intent - Fatal编程技术网

在android中共享应用程序链接和apk文件

在android中共享应用程序链接和apk文件,android,android-intent,share-button,explicit-intent,Android,Android Intent,Share Button,Explicit Intent,我为apk和链接共享创建了一个按钮链接共享工作正常,但当应用程序将共享时,apk名称将更改为“untitled”,我希望与我的apk名称相同 我的链接代码 btnShare.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ApplicationInfo app = getApplicationContext().g

我为apk和链接共享创建了一个按钮链接共享工作正常,但当应用程序将共享时,apk名称将更改为“untitled”,我希望与我的apk名称相同

我的链接代码

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"));
        }
    });

如果你想共享你的应用程序链接和apk文件,请将其作为单独的任务进行。(带两个按钮)

共享链接可以像你提到的那样,因为它是一个文本

要共享apk文件,首先您需要将您的应用程序apk文件作为

 ApplicationInfo packageinfo = context.getPackageManager().getApplicationInfo(yourpackagename, 0);
 File file = new File(packageinfo.publicSourceDir);
然后将文件复制到另一个

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();
}
来源是

您可以使用创建的文件路径共享它

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"));

这将根据所选应用程序将内容更改为text/apk

如果您想共享应用程序链接和apk文件,请将其作为单独的任务进行。(带两个按钮)

共享链接可以像你提到的那样,因为它是一个文本

要共享apk文件,首先您需要将您的应用程序apk文件作为

 ApplicationInfo packageinfo = context.getPackageManager().getApplicationInfo(yourpackagename, 0);
 File file = new File(packageinfo.publicSourceDir);
然后将文件复制到另一个

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();
}
来源是

您可以使用创建的文件路径共享它

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"));

这将根据所选应用程序将内容更改为text/apk

AFAIK我认为这是不可能的。您可以共享指向应用程序的链接,但不能强制数据共享应用程序在不在设备存储上的某些链接上共享文件。除非这是共享应用程序的一项功能(如xander或sharIt)。好吧,我认为这是不可能的。您可以共享指向应用程序的链接,但不能强制数据共享应用程序在不在设备存储上的某些链接上共享文件。除非这是共享应用程序(如xander或sharIt)的一项功能。非常感谢您的回复,但它们可能是一个按钮就能完成的任务???您可以做到;)很抱歉让我回复,但我在文件路径中遇到错误您可以使用packageinfo.sourceDir代替标题使用packageinfo.sourceDir替换为文件路径,但也会遇到错误非常感谢您的回复,但它们都有可能通过一个按钮完成任务???您可以做到;)很抱歉,让我们回复,但我在文件路径中遇到错误。您可以使用packageinfo.sourceDir代替文件路径使用packageinfo.sourceDir替换,但也会遇到错误