googlesamples / android-play-safetynet

Samples for the Google SafetyNet Attestation API
Apache License 2.0
285 stars 133 forks source link

How to register receiver for get SafetyNet actions #31

Closed hoseinimohamad closed 3 years ago

hoseinimohamad commented 3 years ago

I want to use the broadcast receiver to get SafetyNet actions for examples:

 IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(VerifyAppsConstants.ACTION_HARMFUL_APP_BLOCKED);
        intentFilter.addAction(VerifyAppsConstants.ACTION_HARMFUL_APP_INSTALLED);
        intentFilter.addAction(VerifyAppsConstants.ACTION_HARMFUL_APPS_FOUND);
        registerReceiver(new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {

                try {
                    Log.d(TAG, intent.getAction());
                    Toast.makeText(context, intent.getAction(), Toast.LENGTH_SHORT).show();
                    Log.d(TAG, intent.getExtras().toString());
                } catch (Exception e) {
                    Log.d(TAG, e.getMessage());
                }

            }
        }, intentFilter); // called in onCreate

But after registering the receiver and install harmful apps. not received any actions from SafetyNet

you can see google play service document

public static final String ACTION_HARMFUL_APPS_FOUND
An action that is broadcasted when harmful apps are discovered.

Constant Value: "com.google.android.gms.safetynet.action.HARMFUL_APPS_FOUND"
public static final String ACTION_HARMFUL_APP_BLOCKED
An action that is broadcasted when a harmful app is blocked from installation.

Constant Value: "com.google.android.gms.safetynet.action.HARMFUL_APP_BLOCKED"
public static final String ACTION_HARMFUL_APP_INSTALLED
An action that is broadcasted when a harmful app is installed.

Constant Value: "com.google.android.gms.safetynet.action.HARMFUL_APP_INSTALLED"

Google Play Service Actions