在使用GMail app android附加apk文件时,Permisssion被拒绝

在使用GMail app android附加apk文件时,Permisssion被拒绝,第1张

概述我有一个要求通过共享Intent发送apk文件,我也没有任何麻烦.但问题出现在通过GMail发送apk时,我在尝试附加时获得了许可被拒绝.我真的不知道GMail发生了什么.请帮助我完成您的答案和解决方案.任何小提示和技巧对我都有用.提前致谢我使用以下代码使用共享意图发送APK:publicstati

我有一个要求通过共享Intent发送apk文件,我也没有任何麻烦.但问题出现在通过GMail发送apk时,我在尝试附加时获得了许可被拒绝.我真的不知道GMail发生了什么.请帮助我完成您的答案和解决方案.任何小提示和技巧对我都有用.提前致谢

我使用以下代码使用共享意图发送APK:

 public static voID appSend(ArrayList<file> files,Context context){        Intent shareIntent = new Intent(Intent.ACTION_SEND_MulTIPLE);        shareIntent.setType("application/vnd.androID.package-archive");        shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_reset);        ArrayList<Uri> urifiles = new ArrayList<Uri> ();        for(file file: files) {            urifiles.add (Uri.fromfile (file));        }        shareIntent.putParcelableArrayListExtra (Intent.EXTRA_STREAM, urifiles);        try {            context.startActivity (Intent.createChooser (shareIntent, "Share via"));        } catch (androID.content.ActivityNotFoundException ex) {            Toast.makeText (context, "There are no share applications installed.", Toast.LENGTH_SHORT).show();        }    }

AndroIDManifest.xml中:

    <?xml version="1.0" enCoding="utf-8"?><manifest xmlns:androID="http://schemas.androID.com/apk/res/androID"    package="com.sample.share"    androID:versionCode="2"    androID:versionname="1.1">    <uses-permission androID:name="androID.permission.WRITE_INTERNAL_STORAGE" />    <uses-permission androID:name="androID.permission.WRITE_EXTERNAL_STORAGE" />    <uses-permission androID:name="ANDROID.PERMISSION.READ_EXTERNAL_STORAGE"/>    <uses-feature        androID:glEsversion="0x00020000"        androID:required="true" />    <application        androID:allowBackup="true"        androID:icon="@mipmap/ic_launcher"        androID:label="@string/app_name">        <activity            androID:name="com.sample.share.SplashActivity"            androID:label="@string/app_name"            androID:theme="@style/theme.AppCompat.light.NoActionbar.FullScreen">            <intent-filter>                <action androID:name="androID.intent.action.MAIN" />                <category androID:name="androID.intent.category.LAUNCHER" />            </intent-filter>        </activity>        <activity            androID:name="com.sample.share.LandingScreenActivity"            androID:label="@string/app_name"            androID:theme="@style/theme.AppCompat.light.NoActionbar.FullScreen"/>        <activity            androID:name="com.sample.share.MainActivity"            androID:label="@string/app_name"            androID:theme="@style/Sharetoolbar"/>    </application></manifest>

适配器类,用于获取设备中存在的应用程序列表
ShowAppsAdapter.java

public class ShowAppsAdapter extends RecyclerVIEw.Adapter<ShowAppsAdapter.VIEwHolder> implements Filterable{    private Context context;    private static List pkgAppsList;    private List pkgAppsListOriginal;    private int mLayout;    private ArrayList<file> mfileList;    static OnItemClickListener mItemClickListener;    private ItemFilter filter = new ItemFilter();    private HashMap<String,Boolean> itemChecked = new HashMap<String,Boolean>();    private Typeface tf;    public ShowAppsAdapter(Context context, List pkgAppsList, int layout, Typeface tf) {        this.context = context;        this.pkgAppsList = pkgAppsList;        this.pkgAppsListOriginal = pkgAppsList;        this.mLayout = layout;        this.mfileList = new ArrayList<file> ();        this.tf = tf;        for (int i = 0; i < this.getItemCount (); i++) {            itemChecked.put ((String) ((ResolveInfo) pkgAppsList.get (i)).loadLabel (context.getPackageManager ()), false); // initializes all items value with false        }    }    @OverrIDe    public VIEwHolder onCreateVIEwHolder(VIEwGroup vIEwGroup, int i) {        VIEw v = LayoutInflater.from(vIEwGroup.getContext()).inflate(mLayout, vIEwGroup, false);        return new VIEwHolder(v);    }    @OverrIDe    public voID onBindVIEwHolder(final VIEwHolder holder, final int position) {        final ResolveInfo info = (ResolveInfo) pkgAppsList.get(position);        final file file = new file(info.activityInfo.applicationInfo.publicSourceDir);        String appSize= (Utils.getfileSize(context, info.activityInfo.applicationInfo.sourceDir));        holder.txtAppname.setText(info.loadLabel(context.getPackageManager()));        holder.txtAppSize.setText(/*info.activityInfo.packagename*/""+appSize);        holder.txtAppname.setTypeface(tf);        holder.txtAppSize.setTypeface(tf);        holder.txtAppIcon.setimageDrawable(info.loadIcon(context.getPackageManager()));        holder.chkTick.setChecked(itemChecked.get(info.loadLabel (context.getPackageManager ())));        holder.chkTick.setonClickListener (new VIEw.OnClickListener () {            @OverrIDe            public voID onClick (VIEw vIEw) {                toggleSelected((String) info.loadLabel (context.getPackageManager ()), holder.chkTick.isChecked(),  file);            }        });    }    private voID toggleSelected (String name, boolean b, file file) {        itemChecked.put (name,b);        if(b){            addAppList(file);        }else{            removeAppList(file);        }    }    private voID addAppList (file file) {        mfileList.add (file);    }    private voID removeAppList (file file) {        mfileList.remove (file);    }    public ArrayList<file> getAppList(){        return mfileList;    }    @OverrIDe    public int getItemCount() {        return pkgAppsList == null ? 0 : pkgAppsList.size();    }    @OverrIDe    public Filter getFilter () {        return filter;    }    public static class VIEwHolder extends RecyclerVIEw.VIEwHolder implements VIEw.OnClickListener {        TextVIEw txtAppname;        TextVIEw txtAppSize;        ImageVIEw txtAppIcon;        CheckBox chkTick;        public VIEwHolder(VIEw itemVIEw) {            super(itemVIEw);            txtAppname = (TextVIEw)itemVIEw.findVIEwByID(R.ID.text_app_name);            txtAppSize = (TextVIEw)itemVIEw.findVIEwByID(R.ID.txt_app_size);            txtAppIcon = (ImageVIEw)itemVIEw.findVIEwByID(R.ID.img_app_icon);            chkTick = (CheckBox)itemVIEw.findVIEwByID (R.ID.chk_tick);            itemVIEw.setonClickListener(this);        }        @OverrIDe        public voID onClick(VIEw v) {            mItemClickListener.onItemClick(v, getAdapterposition (),((ResolveInfo)pkgAppsList.get (getAdapterposition ()))); //OnItemClickListener mItemClickListener;        }    }    public interface OnItemClickListener {        public voID onItemClick (VIEw vIEw, int position, ResolveInfo o);    }    public voID SetonItemClickListener(final OnItemClickListener mItemClickListener) {        this.mItemClickListener = mItemClickListener;    }    @OverrIDe    public long getItemID(int i) {        return i;    }    private class ItemFilter extends Filter{        @OverrIDe        protected FilterResults performFiltering (CharSequence charSequence) {            String searchString = charSequence.toString ().tolowerCase ();            FilterResults results = new FilterResults();            final List List = pkgAppsListOriginal;            int count = List.size();            final List nList = new ArrayList<ResolveInfo>(count);            String filterableString ;            for (int i = 0; i < count; i++) {                final ResolveInfo info = (ResolveInfo) pkgAppsListOriginal.get(i);                filterableString = (String) info.loadLabel (context.getPackageManager ());                if (filterableString.tolowerCase().contains(searchString)) {                    nList.add(pkgAppsListOriginal.get (i));                }            }            results.values = nList;            results.count = nList.size();            return results;        }        @OverrIDe        protected voID publishResults (CharSequence charSequence, FilterResults filterResults) {            pkgAppsList = (List) filterResults.values;            notifyDataSetChanged ();        }    }}

解决方法:

在应用程序之间共享文件时,应根据setting up file sharing training使用FileProvider,因为这可确保接收应用程序无需任何权限即可读取文件.自AndroID 6.0起,Gmail不会请求存储权限,这意味着它无法读取您使用Uri.fromfile()提供的任何文件.

您将在清单中声明一个fileProvIDer:

<provIDer        androID:name="androID.support.v4.content.fileProvIDer"        androID:authoritIEs="com.example.myapp.fileprovIDer"        androID:grantUriPermissions="true"        androID:exported="false">        <Meta-data            androID:name="androID.support.file_PROVIDER_PATHS"            androID:resource="@xml/filepaths" /></provIDer>

一个XML文件(在本例中称为filepaths.xml以匹配上面的清单声明),它确定哪些目录可通过fileProvIDer获得:

<paths>    <files-path path="images/" name="myimages" /></paths>

然后,代替使用Uri.fromfile(文件),使用FileProvider.getUriForFile(),传递与清单中相同的权限.

总结

以上是内存溢出为你收集整理的在使用GMail app android附加apk文件时,Permisssion被拒绝全部内容,希望文章能够帮你解决在使用GMail app android附加apk文件时,Permisssion被拒绝所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1099232.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存