当sdcard穿上时我怎么能自动安装apk?

no *_*ain 5 android android-intent android-sdcard

我什么都不知道.如何在sdcard上安装时自动安装apk?

但是,我有一个问题,当我注册听取ACTION_MEDIA_SHAREDAndroidManifest.xml Em中的接收器时...我创建了一个扩展的接收器BroadcastReceive,我覆盖OnReceive().但是,最后,接收者无法获得任何行动.这是我的代码.令人沮丧的!!!!!

<receiver android:name=".SdcardPutOnListener"
    android:exported="true">

    <intent-filter>
        <action android:name="android.intent.action.ACTION_MEDIA_BAD_REMOVAL" />
        <action android:name="android.intent.action.ACTION_MEDIA_MEDIA_CHECKING" />
        <action android:name="android.intent.action.ACTION_MEDIA_EJECT" />
        <action android:name="android.intent.action.ACTION_MEDIA_MOUNTED" />
        <action android:name="android.intent.action.ACTION_MEDIA_NOFS" />
        <action android:name="android.intent.action.ACTION_MEDIA_REMOVED" />
        <action android:name="android.intent.action.ACTION_MEDIA_SHARED" />
        <action android:name="android.intent.action.ACTION_MEDIA_UNMOUNTABLE" />
        <data android:scheme="file" /> 
        <category android:name="android.intent.category.HOME"/>
    </intent-filter>
</receiver>

public class SdcardPutOnListener extends BroadcastReceiver {
    final static String TAG = "SdcardPutOnListener";
    public void onReceive(Context context, Intent intent) {
        Log.i(TAG, "receive broadcast " + intent.getAction()); 
    }
}
Run Code Online (Sandbox Code Playgroud)

Com*_*are 3

您可以创建一个应用程序来监视ACTION_MEDIA_MOUNTED广播,然后在已知位置的外部存储中查找 APK 文件,然后startActivity()使用ACTION_VIEW Intent正确的 MIME 类型 ( application/vnd.android.package-archive) 调用该 APK 文件的路径。

如果您希望将其内置到操作系统中,那么事实并非如此。