مشکل در ارسال apk از داخل برنامه (حل شد)
من برای ارسال فایل apk از داخل برنامه از این کد استفاده می کنم . اما نمیدونم چرا با shareapp خطا میده..
btnShare.setOnClickListener(newOnClickListener(){
@Override
publicvoid onClick(View v){
shareApp (G.context ,"Share App")// or shareApp (ActivityName.this , "Share App")
}
});
// ارسال برنامه از طرق مختلف
publicstaticvoid shareApp (Context context ,String title){
try{
PackageManager pm = context.getPackageManager();
ApplicationInfo ai = pm.getApplicationInfo(context.getPackageName(),0);
File srcFile =newFile(ai.publicSourceDir);
Intent share =newIntent();
share.setAction(Intent.ACTION_SEND);
share.setType("application/*");
share.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(srcFile));
context.startActivity(Intent.createChooser(share, title));
}catch(Exception e){
}
}
من برای ارسال apk از کد زیر استفاده میکنم مشکلی هم ندارم:
try{
ArrayList<Uri> uris = new ArrayList<Uri>();
Intent sendIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
sendIntent.setType("application/vnd.android.package-archive");
uris.add(Uri.fromFile(new File(getApplicationInfo().publicSourceDir)));
sendIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
startActivity(Intent.createChooser(sendIntent, null));
}catch(Exception e){
ArrayList<Uri> uris = new ArrayList<Uri>();
Intent sendIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
sendIntent.setType("application/zip");
uris.add(Uri.fromFile(new File(getApplicationInfo().publicSourceDir)));
sendIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
startActivity(Intent.createChooser(sendIntent, null));
}
از این هم میتونی استفاده کنی:
public static void sendAppItself(Activity paramActivity, String paramStringToastMsg) throws IOException {
Toast.makeText(paramActivity, paramStringToastMsg, Toast.LENGTH_LONG).show();
PackageManager pm = paramActivity.getPackageManager();
ApplicationInfo appInfo;
try {
appInfo = pm.getApplicationInfo(paramActivity.getPackageName(),
PackageManager.GET_META_DATA);
Intent sendBt = new Intent(Intent.ACTION_SEND);
// NOT THIS! sendBt.setType("application/vnd.android.package-archive");
sendBt.setType("*/*");
sendBt.putExtra(Intent.EXTRA_STREAM,
Uri.parse("file://" + appInfo.publicSourceDir));
Log.v("PACKAGEDIR: ", appInfo.publicSourceDir);
paramActivity.startActivity(Intent.createChooser(sendBt, "Share image using"));
// paramActivity.startActivity(sendBt);
}
catch (NameNotFoundException e1) {
e1.printStackTrace();
}
}
پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .
