yy1717
2020-12-17 9081551057d67fc4c26f5b8ffd47506690797ff6
坐标
1个文件已添加
30 ■■■■■ 已修改文件
app/src/main/java/safeluck/drive/evaluation/receiver/PackageReceiver.java 30 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/receiver/PackageReceiver.java
New file
@@ -0,0 +1,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();
        }
    }
}