在意图过滤器中没有操作,尝试安装应用程序

时间:2014-12-25 02:23:10

标签: android android-intent android-install-apk

我创建了一个使用PackageManager安装下载的APK文件的类。但是当我尝试安装一个时,我在logcat中收到以下消息:

12-25 03:11:32.014: W/PackageParser(11192): No actions in intent filter at /storage/emulated/0/download/test/test.apk Binary XML file line #22

我使用以下代码安装应用程序:

case R.id.view_application_install: {
            final File apk = Util.getApk(downloadedItem.getDirectory());
            final Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.fromFile(apk), "application/vnd.android.package-archive");
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        }

这是清单的一部分:

<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="org.catares.android"
android:versionName="@string/app_version"
android:versionCode="9">
<uses-sdk 
    android:minSdkVersion="4"
    android:targetSdkVersion="21" />

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RAISED_THREAD_PRIORITY" />

<application
    android:icon="@drawable/icon"
    android:label="@string/app_name">       
    <activity
        android:configChanges="keyboard|keyboardHidden|orientation"
        android:name=".Main"
        android:launchMode="singleTop">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".application.ApplicationActivity" 
        android:configChanges="keyboard|keyboardHidden|orientation"              
        android:exported="false">
        <intent-filter>
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name=".application.ImageViewActivity" 
        android:configChanges="keyboard|keyboardHidden|orientation"              
        android:exported="false">
        <intent-filter>
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name=".categories.CategoriesActivity" 
        android:configChanges="keyboard|keyboardHidden|orientation"              
        android:exported="false">
        <intent-filter>
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:configChanges="keyboard|keyboardHidden|orientation"
        android:name=".forum.ViewForumActivity"
        android:exported="false" >
        <intent-filter>
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>     
    <activity
        android:name=".latest.LatestReleasesActivity" 
        android:configChanges="keyboard|keyboardHidden|orientation"              
        android:exported="false">
        <intent-filter>
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name=".myapplications.MyApplicationsActivity" 
        android:configChanges="keyboard|keyboardHidden|orientation"              
        android:exported="false">
        <intent-filter>
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name=".myapplications.ViewApplicationActivity" 
        android:configChanges="keyboard|keyboardHidden|orientation"              
        android:exported="false">
        <intent-filter>
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name=".myapplications.installed.UpdateSearchResultActivity" 
        android:configChanges="keyboard|keyboardHidden|orientation"              
        android:exported="false">
        <intent-filter>
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity 
        android:name=".search.SearchActivity"
        android:configChanges="keyboard|keyboardHidden|orientation"
        android:exported="false" >
        <intent-filter>
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name=".application.replies.RepliesActivity"
        android:configChanges="keyboard|keyboardHidden|orientation"         
        android:exported="false" >
        <intent-filter>
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name=".settings.SettingsActivity"
        android:configChanges="keyboard|keyboardHidden|orientation"
        android:exported="false" >
        <intent-filter>
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name=".downloads.DownloadsActivity"
        android:configChanges="keyboard|keyboardHidden|orientation"
        android:exported="false" >
        <intent-filter>
            <category android:name="android.intent.category.DEFAULT"/>
        </intent-filter>
    </activity>
    <service android:name=".common.UpdaterService"/>
    <service android:name=".common.downloads.DownloaderService"/>
</application>  
</manifest>

第22行显示logcat中的错误:

<action android:name="android.intent.action.MAIN" />

1 个答案:

答案 0 :(得分:0)

您必须在所有意图过滤器中包含操作标记。 以下是一个例子:

<intent-filter>
        <action android:name="android.intent.action.SEND"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <data android:mimeType="text/plain"/>
    </intent-filter>

您只是定义了intent过滤器的类别,而没有定义Activity将处理的操作。