lizhanwei
2021-04-26 7fdc4fa80d5d04b5936fc1bdd617b64c6ae9ef37
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package safeluck.drive.evaluation.receiver;
 
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;
 
import safeluck.drive.evaluation.MainActivity;
 
public class PackageReceiver extends BroadcastReceiver {
 
    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO: This method is called when the BroadcastReceiver is receiving
        // an Intent broadcast.
//        throw new UnsupportedOperationException("Not yet implemented");
         if (intent.getAction().equals("android.intent.action.PACKAGE_ADDED") ||
                intent.getAction().equals("android.intent.action.PACKAGE_REPLACED")) {
             String pktName =intent.getData().getSchemeSpecificPart();
            Toast.makeText(context, pktName + "  Install Complete", Toast.LENGTH_LONG).show();
            if (context.getApplicationContext().getPackageName().equals(pktName)) {
                Intent mBootIntent = new Intent(context, MainActivity.class);
                mBootIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(mBootIntent);
            }
        } else {
            Toast.makeText(context, intent.getAction(), Toast.LENGTH_LONG).show();
        }
    }
}