Android报错:Caused by: java.lang.IllegalArgumentException: Service Intent must be explicit: Intent

报错的代码:

Intent downloadIntent = new Intent(Constants.ACTION_DOWNLOADSERVICE);
		downloadIntent.putExtra(MyIntents.TYPE, MyIntents.Types.START);
		startService(downloadIntent);
改正后的代码:

Intent downloadIntent = new Intent(Constants.ACTION_DOWNLOADSERVICE);
		downloadIntent.putExtra(MyIntents.TYPE, MyIntents.Types.START);
		downloadIntent.setPackage(getPackageName());
		this.startService(downloadIntent);
原因: 5.0版本后service的intent要显式声明


你可能感兴趣的:(Android)