据我所知,我们无法在运行时更改应用程序图标。我猜想,上面的示例中的图标可能是一个小部件。
关于更改背景壁纸(或执行特定任务):我认为我们可以创建一个启动器活动(透明的/不带 setContentView()
),该活动将在触发更改壁纸的后台服务(或执行任何其他任务)后finish()
本身。根据我的意见,虽然我个人没有尝试过,但这可以是上述场景的解决方案。
最好的问候,愉快编码 :)
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
public class YourActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set you app icon
setColorWallpaper();
// Finish the activity
finish();
}
/**
* Sets the color wallpaper to the color value in the Clipboard, or to a random color.
*/
private void setColorWallpaper() {
// Try to get the color parameter from the clipboard
Integer colorParam = null;
try {
colorParam = ColorClipboardParameter.getColor(getApplication());
} catch (Exception ignored) {
// An unexpected exception while trying to get the color code from the clipboard
// can crash the app at startup. Ignore any exceptions, we will generate a random
// color anyway.
}
// If there is no valid color value in the clipboard, generate a random color
final int color = (colorParam != null) ? colorParam : GoodRandomColor.nextColor();
try {
// Set the color wallpaper
ColorWallpaper.setColorWallpaper(this, color);
// Success: copy the color code to the clipboard
Utils.copyText(this, Utils.colorToHex(color));
// Go to the home screen
Utils.goHome(this);
} catch (IOException e) {
// Write the stack trace to System.err and copy the reason of the failure to clipboard
e.printStackTrace();
Utils.copyText(this, e.toString());
}
}
}
清单文件:
<application
android:fullBackupContent="true"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:installLocation="auto"
android:label="@string/app_name"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".YourActivity"
android:excludeFromRecents="true"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
请查看此项目获取更多信息:https://github.com/appgramming/LoneColor-Android