简体   繁体   English

安装新apk版本的Android Air本机扩展会引发“未找到任何处理意图的活动”

[英]Android Air Native Extension to install new apk version throws “no activity found to handle intent”

All I want is to install (ask user for) new application version stored on sdcard as .apk file using Adobe Air Native Extension. 我想要做的就是使用Adobe Air Native Extension安装(要求用户使用).apk文件形式存储在sdcard上的新应用程序版本。

Here is my ANE function code: 这是我的ANE功能代码:

@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} 找不到可处理意图的活动{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. 说该文件是真实的,并且args [0]路径正确。

After hours of google i found that the problem was in missing "file://" 几个小时的Google之后,我发现问题出在“ file://”丢失了

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

Now everything work fine! 现在一切正常!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM