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

时间:2014-04-12 08:07:57

标签: android

你好朋友那里有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 

1 个答案:

答案 0 :(得分:1)

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

  • 在Mainfest.xml中定义<intent-filter>
  • Intent方法检查onCreate ..
  • Intent以活动结果
  • 托管活动

如果您想将图像/文本分享给其他应用程序,则有两种方式..

  1. 与主叫应用程序分享图像
  2. 为此,您必须使用android.intent.action.SEND过滤器

    1. 回答主机申请图像请求
    2. 为此,您必须使用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

      中的OnCreate
      @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();        
              }
          }
      }