インテント内に .apk ファイルを追加したい。Bluetoothまたはアプリケーションを送信する機能を持つ他のアプリケーションを介してアプリ全体を共有するボタン「共有」を作成したいと考えています。これが他の方法でできる場合は、教えてください!ありがとう
3211 次
5 に答える
2
List(ApplicationInfo) mAppList=getPackageManager().getInstalledApplications(0);
ApplicationInfo item = mAppList.get(position);
public static void ShareAPK(ApplicationInfo item,Context ctx) {
try {
File srcFile = new File(item.publicSourceDir);
Intent share = new Intent();
share.setAction(Intent.ACTION_SEND);
share.setType("application/vnd.android.package-archive");
share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(srcFile));
ctx.startActivity(Intent.createChooser(share, "Sharing"));
} catch (Exception e) {
e.printtrace();
}
}
于 2015-03-31T05:43:11.823 に答える
1
バイナリ データは、ACTION_SEND アクションを適切な MIME タイプの設定と組み合わせて使用し、データへの URI を EXTRA_STREAM という名前のエクストラに配置して共有されます。これは一般的にイメージを共有するために使用されますが、あらゆる種類のバイナリ コンテンツを共有するために使用できます。
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, uriToImage);
shareIntent.setType("application/vnd.android.package-archive");
startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to)));
詳細については; これを参照してください:バイナリデータを送信する
于 2014-07-26T08:34:17.297 に答える
0
Bluetooth を使用してアプリ内で .apk ファイルを送信 (共有) する場合は、これを使用します
// Get current ApplicationInfo to find .apk path
ApplicationInfo app = getApplicationContext().getApplicationInfo();
String filePath = app.sourceDir;
Intent intent = new Intent(Intent.ACTION_SEND);
// MIME of .apk is "application/vnd.android.package-archive".
// but Bluetooth does not accept this. Let's use "*/*" instead.
intent.setType("*/*");
// Only use Bluetooth to send .apk
intent.setPackage("com.android.bluetooth");
// Append file and send Intent
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(filePath)));
startActivity(Intent.createChooser(intent, "Share app"));
于 2015-05-03T15:34:44.017 に答える
0
アプリの APK の場所を追加できます
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("*/*");
shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
Uri uri = Uri.parse("/data/apps/"+getApplicationContext().getPackageName()+".apk");
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(shareIntent, "Share via"));
SecurityExceptionアプリまたは共有アプリがファイルにアクセスできない場合に発生する可能性があることに注意してください
于 2014-07-20T17:08:08.823 に答える
0
public void shareAPKMine()
{
try {
PackageManager m = getPackageManager();
String s = getPackageName();
PackageInfo p = m.getPackageInfo(s, 0);
s = p.applicationInfo.sourceDir;
File sourceLocation = new File(s);
String path = Environment.getExternalStorageDirectory().getAbsolutePath()+"/shefi/"+"test.apk";
File targetLocation = new File(path);
Utils.copyDirectory(sourceLocation, targetLocation);
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("application/vnd.android.package-archive");
shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
Uri uri = Uri.parse(path);
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(shareIntent, "Share"+" "+getResources().getString(R.string.app_name)));
}catch (Exception e) {
e.printStackTrace();
}
}
// If targetLocation does not exist, it will be created.
public static void copyDirectory(File sourceLocation , File targetLocation)
throws IOException {
if (sourceLocation.isDirectory()) {
if (!targetLocation.exists() && !targetLocation.mkdirs()) {
throw new IOException("Cannot create dir " + targetLocation.getAbsolutePath());
}
String[] children = sourceLocation.list();
for (int i=0; i<children.length; i++) {
copyDirectory(new File(sourceLocation, children[i]),
new File(targetLocation, children[i]));
}
} else {
// make sure the directory we plan to store the recording in exists
File directory = targetLocation.getParentFile();
if (directory != null && !directory.exists() && !directory.mkdirs()) {
throw new IOException("Cannot create dir " + directory.getAbsolutePath());
}
InputStream in = new FileInputStream(sourceLocation);
OutputStream out = new FileOutputStream(targetLocation);
// Copy the bits from instream to outstream
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
}
}
于 2015-03-04T02:45:38.843 に答える