gpt4 book ai didi

android - 如何以编程方式通过我的应用程序更改 whatsapp 壁纸?

转载 作者:行者123 更新时间:2023-11-30 02:57:34 26 4
gpt4 key购买 nike

你好 friend ,whatsapp 中有一个选项,我们可以通过它更改 whatsapp 聊天的背景墙纸。我正在制作一个项目,其中我提供了很多壁纸,我想从我的壁纸列表中设置壁纸

我使用了这段代码,但代码不起作用

Intent shareIntent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("image/*");
Uri uri = Uri.parse("android.resource://com.mypackagename/"+R.drawable.image);
shareI
ntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(shareIntent, "Share via"));Intent = new

最佳答案

为了允许其他应用程序调用您的应用程序或请求,您必须定义两件事..

  • 定义<intent-filter>在 Mainfest.xml 中
  • 检查 IntentonCreate方法..
  • Intent以 Activity RESULT 举办 Activity

如果你想在其他通话中将你的图像/文本分享到其他应用程序,有两种方式..

  1. 与随叫随到的主机应用程序分享图像

为此你必须使用 android.intent.action.SEND过滤器

  1. 回答主机申请的图像请求

为此你必须使用 android.intent.action.PICK过滤器

list .xml

<application
android:allowBackup="true"
android:icon="@drawable/image1"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />

<!-- share your image with host application -->
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>

<!-- answer to host application for image request -->
<action android:name="android.intent.action.PICK"/>
<category android:name="android.intent.category.OPENABLE"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:mimeType="image/*"/>
</intent-filter>
</activity>
</application>

MainActivity 中创建

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// get intent from host activity
Intent intent = getIntent();
if(!intent.getAction().equals("android.intent.action.MAIN")){

// check about request
if (intent.getAction().equals("android.intent.action.PICK")) {

// return to activity with result OK and image selected image
Intent result = new Intent("com.example.RESULT_ACTION", Uri.parse("content://result_uri"));
setResult(Activity.RESULT_OK, result);
finish();
}
}
}

关于android - 如何以编程方式通过我的应用程序更改 whatsapp 壁纸?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23027904/

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