我需要在点击通知时启动更新Android操作系统 我正在使用此代码:
Intent callGPSSettingIntent =new Intent(android.provider.Settings.ACTION_DEVICE_INFO_SETTINGS);
startActivityForResult(callGPSSettingIntent,1);
但它只将用户移动到“关于设备”部分,然后用户可以看到软件更新选项。
我的要求是再深一步,当用户点击通知时,软件更新会自动启动。
答案 0 :(得分:1)
从活动中调用此函数:
openSettingsPage(this, "android.settings.SYSTEM_UPDATE_SETTINGS");
和
public void openSettingsPage(Context context, String setting) {
Intent intent = new Intent(setting, null);
final boolean isAndroidJellyBean = Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN
&& Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT;
if (isAndroidJellyBean || !areSettingsAvailable(context, intent)) {
intent = new Intent(Settings.ACTION_SETTINGS);
}
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
public Boolean areSettingsAvailable(Context context, Intent intent) {
List<ResolveInfo>
activities = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
return activities != null && activities.size() > 0;
}