android - I use DownloadManager.ACTION_DOWNLOAD_COMPLETE but occur ActivityNotFoundException -
i want apk in server, after install apk on android
but when install apk shows activitynotfoundexception.
perhaps, permission problem?
<uses-permission android:name="android.permission.internet"/> <uses-permission android:name="android.permission.write_external_storage"/>
thanks please advice me
this source
public class mainactivity extends appcompatactivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); button btn = (button) findviewbyid(r.id.btn); btn.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { string url = "myserver/apk"; file apkfile = new file("/sdcard/download/openapk.apk"); uri muri = uri.parse(url); downloadmanager.request r = new downloadmanager.request(muri); r.setdestinationinexternalpublicdir(environment.directory_downloads, "openapk.apk"); r.setnotificationvisibility(downloadmanager.request.visibility_visible_notify_completed); downloadmanager dm = (downloadmanager) getsystemservice(context.download_service); dm.enqueue(r); // } }); } private broadcastreceiver completereceiver = new broadcastreceiver() { @override public void onreceive(context context, intent intent) { file apkfile = new file("/sdcard/download/openapk.apk"); uri apkuri = uri.fromfile(apkfile); intent webintent = new intent(intent.action_view); webintent.setdataandtype(uri.fromfile(apkfile), "application/vnd.android.pacvkage-archive"); webintent.setflags(intent.flag_activity_new_task); startactivity(webintent); //activitynotfoundexception } }; @override public void onresume() { super.onresume(); intentfilter completefilter = new intentfilter(downloadmanager.action_download_complete); registerreceiver(completereceiver, completefilter); } } fatal exception: main process: company.co.kr.urlupdater, pid: 23341 java.lang.runtimeexception: error receiving broadcast intent { act=android.intent.action.download_complete flg=0x10 pkg=company.co.kr.urlupdater (has extras) } in company.co.kr.urlupdater.mainactivity$2@2184e240 @ android.app.loadedapk$receiverdispatcher$args.run(loadedapk.java:769) @ android.os.handler.handlecallback(handler.java:733) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:136) @ android.app.activitythread.main(activitythread.java:5001) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:515) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:785) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:601) @ dalvik.system.nativestart.main(native method) caused by: android.content.activitynotfoundexception: no activity found handle intent { act=android.intent.action.view dat=file:///sdcard/download/openapk.apk typ=application/vnd.android.pacvkage-archive flg=0x10000000 } @ android.app.instrumentation.checkstartactivityresult(instrumentation.java:1632) @ android.app.instrumentation.execstartactivity(instrumentation.java:1424) @ android.app.activity.startactivityforresult(activity.java:3424) @ android.app.activity.startactivityforresult(activity.java:3385) @ android.support.v4.app.fragmentactivity.startactivityforresult(fragmentactivity.java:843) @ android.app.activity.startactivity(activity.java:3627) @ android.app.activity.startactivity(activity.java:3595) @ company.co.kr.urlupdater.mainactivity$2.onreceive(mainactivity.java:64) @ android.app.loadedapk$receiverdispatcher$args.run(loadedapk.java:759) @ android.os.handler.handlecallback(handler.java:733) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:136) @ android.app.activitythread.main(activitythread.java:5001) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:515) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:785) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:601) @ dalvik.system.nativestart.main(native method)
i guess have typo while setting package name intent
. should "application/vnd.android.package-archive". whole line be:
webintent.setdataandtype(uri.fromfile(apkfile), "application/vnd.android.package-archive");
that's why got activitynotfoundexception
, cause give wrong package, , proper activity
can't found.
Comments
Post a Comment