What Intent Filter can I use to capture intent cal

2019-08-29 02:42发布

问题:

I am creating an app that warns users about strange permission requests before they download an app from the Android Market (such as a wallpaper app that requests to read a user's contact information). Is there a way to capture the intent called when a user presses the install button and is shown the list of uses-permissions?

回答1:

There's no way of doing this that I know of. You can show the user your dialog right after the user installs the app instead (in most cases, before they run it):

AndroidManifest.xml

<receiver android:name=".Receiver">
    <intent-filter>
        <action android:name="android.intent.action.PACKAGE_ADDED" />
        <action android:name="android.intent.action.PACKAGE_CHANGED"/>
        <data android:scheme="package"/>
    </intent-filter>
</receiver>

Receiver.java

public class Receiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
          try {
              PackageManager manager = this.getPackageManager();
              PackageInfo info = manager.getPackageInfo(
                  intent.getData().getSchemeSpecificPart(), 0);
              Toast.makeText(context, "Look at these suspicious permissions:"+
                  info.permissions, Toast.LENGTH_LONG).show();
          } catch (Exception e) {}
    }
}