安装第三方应用程序时,如果未勾选允许安装非电子市场提供的应用程序,则无法正常安装应用程序。
可以给用户提示,需要开启这个选项。
<string name="nonmarket">请勾选设置:\n\"允许安装非电子市场提供的应用程序\"</string> <string name="ok">确定</string> <string name="cancel">取消</string>
private boolean checkNonMarketAppEnabled() { int result = Settings.Secure.getInt(getContentResolver(), Settings.Secure.INSTALL_NON_MARKET_APPS, 0); if (result == 0) { //Toast.makeText(getApplicationContext(), "Please enable Unkown resource\n to install your app.", 2000); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("重要提示"); builder.setMessage(this.getResources().getString(R.string.nonmarket)) .setCancelable(false) .setPositiveButton(this.getResources().getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Intent intent = new Intent(); intent.setAction(Settings.ACTION_APPLICATION_SETTINGS); startActivity(intent); } }); AlertDialog alert = builder.create(); alert.show(); return false; } return true; }
数据库为:
/data/data/com.android.providers.settings/databases/settings.db
secure表中的install_non_market_apps值修改为1:
sql:
update secure set value = 1 where name='install_non_market_apps';