android编程怎么发送,如何在android中以编程方式使用share intent发...

我认为这应该对你有帮助

ArrayList arrayListapkFilepath; // define global

//put this code when you wants to share apk

arrayListapkFilepath = new ArrayList();

shareAPK(getPackageName());

// you can pass bundle id of installed app in your device instead of getPackageName()

Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);

intent.setType("application/vnd.android.package-archive");

intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM,

arrayListapkFilepath);

startActivity(Intent.createChooser(intent, "Share " +

arrayListapkFilepath.size() + " Files Via"));

//Method

public void shareAPK(String bundle_id) {

File f1;

File f2 = null;

final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);

mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);

final List pkgAppsList = getPackageManager().queryIntentActivities(mainIntent, 0);

int z = 0;

for (Object object : pkgAppsList) {

ResolveInfo info = (ResolveInfo) object;

if (info.activityInfo.packageName.equals(bundle_id)) {

f1 = new File(info.activityInfo.applicationInfo.publicSourceDir);

Log.v("file--",

" " + f1.getName().toString() + "----" + info.loadLabel(getPackageManager()));

try {

String file_name = info.loadLabel(getPackageManager()).toString();

Log.d("file_name--", " " + file_name);

f2 = new File(Environment.getExternalStorageDirectory().toString() + "/Folder");

f2.mkdirs();

f2 = new File(f2.getPath() + "/" + file_name + ".apk");

f2.createNewFile();

InputStream in = new FileInputStream(f1);

OutputStream out = new FileOutputStream(f2);

// byte[] buf = new byte[1024];

byte[] buf = new byte[4096];

int len;

while ((len = in.read(buf)) > 0) {

out.write(buf, 0, len);

}

in.close();

out.close();

System.out.println("File copied.");

} catch (FileNotFoundException ex) {

System.out.println(ex.getMessage() + " in the specified directory.");

} catch (IOException e) {

System.out.println(e.getMessage());

}

}

}

arrayListapkFilepath.add(Uri.fromFile(new File(f2.getAbsolutePath())));

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值