android代码安装报错No activity found to handle Intent error

在尝试使用Adobe Air Native Extension在Android设备上安装存储在SD卡上的.apk文件时,遇到'No activity found to handle Intent'错误。问题在于Intent中缺少'file://'前缀。修复此问题后,能够正常执行安装应用的流程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://stackoverflow.com/questions/25053598/android-air-native-extension-to-install-new-apk-version-throws-no-activity-foun

All I want is to install (ask user for) new application version stored on sdcard as .apk file using Adobe Air Native Extension.

Here is my ANE function code:

@Override
//args[0] is the path to local stored apk (logs as /storage/sdcard0/testStorage/updates/1.1apk)
public FREObject call(FREContext _context, FREObject[] args) {
     context = _context;

     try {             
         Intent promptInstall = new Intent(Intent.ACTION_VIEW);
         promptInstall.setDataAndType(Uri.parse(args[0].getAsString()), "application/vnd.android.package-archive");
         promptInstall.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         context.getActivity().startActivity(promptInstall);

         alert("Okay", "start was!"); //using AlertDialog for debug purpose

     } catch (Exception e) {
             alert("Error!", e.getLocalizedMessage());
             e.printStackTrace();
     } 

 return null;
}

And here is manifest I'm using:

 <android>
    <manifestAdditions><![CDATA[<manifest android:installLocation="auto">
    <uses-sdk android:minSdkVersion="8" />
    <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-feature android:name="android.hardware.microphone" android:required="false" />
    <application android:hardwareAccelerated="true" />
    <application android:debuggable="true"/>
    <application>
        <activity android:name="android.intent.action.VIEW">
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

    <uses-permission android:name="android.permission.INSTALL_PACKAGES" />
    <uses-permission android:name="android.permission.RESTART_PACKAGES"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-feature android:required="true" android:name="android.hardware.touchscreen.multitouch" />
</manifest>]]></manifestAdditions>
  </android>

But I'm always getting "No activity found to handle Intent error":

No Activity found to handle Intent { act=android.intent.action.VIEW dat=/storage/sdcard0/testStorage/updates/1.1.apk typ=application/vnd.adnroid.package-archive flg=0x10000000}

Added

File setupFile = new File(args[0].getAsString());
alert("Is exists?", Boolean.toString(setupFile .exists())); //output as true

Said that file is real and args[0] path is correct.

解决方法:

After hours of google i found that the problem was in missing "file://"

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("file://" + args[0].getAsString()), "application/vnd.android.package-archive");


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值