gpt4 book ai didi

android - 如何将文本从 Activity 发送到 WallpaperService 类

转载 作者:行者123 更新时间:2023-11-29 14:14:55 25 4
gpt4 key购买 nike

我想将文本从 MainActivity 发送到 WallpaperService 类以绘制文本。

主要 Activity 类-->

Intent in = new Intent();


in.setAction(WallpaperManager.ACTION_LIVE_WALLPAPER_CHOOSER);
in.putExtra("name", "sample text");
startActivity(in);

WallpaperService 类 -->

Bundle bundle = getIntent().getExtras();
String value = bundle.getString("key");

但是 WallpaperService 类中没有 getIntent() 方法。

最佳答案

1) 使用 Intent 中的 Bundle:
Intent mIntent = new Intent(this, Example.class);
Bundle extras = mIntent.getExtras();
extras.putString(键,值)

新上下文(可以是 Activity/服务等)

 Intent myIntent = getIntent(); // this getter is just for example purpose, can differ
if (myIntent !=null && myIntent.getExtras()!=null)
String value = myIntent.getExtras().getString(key);
}

关于android - 如何将文本从 Activity 发送到 WallpaperService 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23539277/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com