你好朋友那里有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
答案 0 :(得分:1)
您必须定义两件事,以允许其他应用程序调用您的应用程序或请求..
<intent-filter>
Intent
方法检查onCreate
.. Intent
以活动结果如果您想将图像/文本分享给其他应用程序,则有两种方式..
为此,您必须使用android.intent.action.SEND
过滤器
为此,您必须使用android.intent.action.PICK
过滤器
的Manifest.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();
}
}
}