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

标签 android android-intent live-wallpaper

我想将文本从 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/

相关文章:

java - 在其 Android SDK 1.11.0 上找不到 ParseCrashReporting-*.jar

java - 如何在从 Android 服务类启动其他 Activity 后关闭 1 个 Activity

android - Wallpaper 中的许可验证库

android - 如何在Android中播放mp4文件中的声音?

Android:如何布局全屏 EditText,下面有一个按钮?

android - 如何使用 espresso android 测试一定范围内的 View 文本

android - 如何在 Android 设备中查找 simcard 是否更改?

android - 无需调用 onoffsetchanged(用于墙纸)即可获取主屏幕数量?

android - 将相机移动到场景中的特定点(旋转/平移时)- OpenGL ES 2

android - 如何直接打开图库应用挑选图片