Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
612 views
in Technique[技术] by (71.8m points)

bluetooth - packing my app and share to other + android

I'm creating an application for Android and I need a button to send my application to another phone.

I tried to put an apk and send to other but I can't do it. I'm using this code :

Intent sharei=new Intent(Intent.ACTION_SEND);
sharei.putExtra(Intent.EXTRA_STREAM,Uri.parse("android.resource://com.packa.ge/raw/hafez.apk"));
sharei.setType("application/vnd.android.package-archive");
startActivity(Intent.createChooser(sharei, "share"));

but it isn't working.


I saw a Persian app do this: in a context menu one of the items was :"Send via Bluetooth" and when I touched this, it sent the apk file to the other phone.

I packed My app and put it to Raw folder to send, but this is not work correctly for 2nd or 3rd phone.

he said: "i create a application for android i need put button to send my application to other phone", i think he is talking about sending the same application he is running....
Andrea Bellitto

Yes. I need to send my running application.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

resolved ...

try {
    PackageManager pm = getPackageManager();
    ApplicationInfo ai = pm.getApplicationInfo(getPackageName(), 0);
    File srcFile = new File(ai.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));
    startActivity(Intent.createChooser(share, "PersianCoders"));
} catch (Exception e) {
    Log.e("ShareApp", e.getMessage());
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...