Permisssion denied while attaching apk file with GMail app android -
i have requirement send apk file through share intent , have implemented without hassle. problem arises while sending apk via gmail, getting permission denied while try attach. dont know happening gmail. kindly me through answers , solutions. small hint , tips useful me. in advance
i using following code send apk using shared intents:
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 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>
adapter class fetch list of apps present in device
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; (int = 0; < this.getitemcount (); i++) { itemchecked.put ((string) ((resolveinfo) pkgappslist.get (i)).loadlabel (context.getpackagemanager ()), false); // initializes items value 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 ; (int = 0; < 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 (); } } }
when sharing files between applications, should use fileprovider per setting file sharing training ensures receiving app can read file without requiring permissions. of android 6.0, gmail not request storage permission, meaning unable read files provide uri.fromfile()
.
you'd declare fileprovider
in manifest:
<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>
an xml file (in case called filepaths.xml
match above manifest declaration) determines directories available via fileprovider
:
<paths> <files-path path="images/" name="myimages" /> </paths>
then, in place of using uri.fromfile(file)
, use fileprovider.geturiforfile()
, passing in same authority in manifest.
Comments
Post a Comment