如何找到apk文件中我的Andr​​oid应用程序的存储路径 [英] how to find my android application's storing path of apk file

查看:173
本文介绍了如何找到apk文件中我的Andr​​oid应用程序的存储路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打,可以通过蓝牙发送自身(apk文件)的应用程序。但我有找到的apk文件路径的麻烦。我想这code:

I want to make an application that could send itself (apk file) by bluetooth. but i have trouble with finding the apk file path. i tried this code:

final PackageManager pm = this.getPackageManager();
    List<PackageInfo> packages =  pm.getInstalledPackages(PackageManager.GET_META_DATA);
    String st = null;
    for (PackageInfo packageInfo : packages) {
        if(packageInfo.packageName.contains("testbutton"))
        st=packageInfo.packageName;
    }

    Intent intent = new Intent();  
    intent.setAction(Intent.ACTION_SEND);  
    intent.setType("image/*");

    String uri = "/data/app/";
    uri+=st;
    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(uri)));
    startActivity(intent);

但ST返回空值。 请帮助我。在此先感谢

but st returns null value. please help me with this. thanks in advance

推荐答案

终于我找到了正确的答案,在这个目的的作品,感谢@Kanak她的帮助:)

finally i'd found the right answer that works in this purpose, thanks to @Kanak for her help :)

PackageManager pm = getPackageManager();
    String uri = null;
    for (ApplicationInfo app : pm.getInstalledApplications(0)) {
        if(!((app.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 1))
            if(!((app.flags & ApplicationInfo.FLAG_SYSTEM) == 1)){
                uri=app.sourceDir;
                  if(uri.contains("com.example.test"))
                  break;
            }
    }

    Intent intent = new Intent();  
    intent.setAction(Intent.ACTION_SEND);  
    intent.setType("image/*");
    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(uri)));
    startActivity(intent);

这篇关于如何找到apk文件中我的Andr​​oid应用程序的存储路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆