1.用淘宝点击分享微信,生成商品口令
2.复制口令字符串
3.写入剪切板,读取剪切板的数据
4.跳转淘宝app,淘宝会自动监听字符串数据,配合后台,弹框拿到商品数据的详情
依赖
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.github.bumptech.glide:glide:3.7.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:cardview-v7:28.0.0'
功能代码:
package com.example.glidedownload;
import android.content.ClipData;
import android.content.ClipDescription;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class FirstActivity extends AppCompatActivity {
private String phone="1\uD83D\uDC48 hi:/\uD83D\uDDDDupvbXU2HWxZ\uD83D\uDDDD Apple/苹果 iPhone 11 移动联通电信4G全网通手机 2020新版";
private String book="4\uD83D\uDC48 hi:/\uD83D\uDCB2AINOXUdS5o3₴ 国富论(上下卷)(权威译本)";
private String table="8\uD83D\uDC48 ha:/✔PEcrXUdiNYn《 SUNSHINE BABY/阳光芭比诺檀丝木小书桌实木桌子客厅家具";
private TextView tv_content;
private Button btn_open;
private String content;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first);
btn_open = findViewById(R.id.btn_open);
tv_content = findViewById(R.id.tv_content);
tv_content.setText(phone);
btn_open.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
content = tv_content.getText().toString();
GangUpInvite(getApplicationContext(), content);
}
});
}
public void GangUpInvite(final Context context, String content) {
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(CLIPBOARD_SERVICE);
ClipData mClipData = ClipData.newPlainText("Label", content);
clipboard.setPrimaryClip(mClipData);
Log.e("TAG","tv_text:"+mClipData+content);
//无数据时直接返回
if (!clipboard.hasPrimaryClip()) {
return;
}
//如果是文本信息
if (clipboard.getPrimaryClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
ClipData cdText = clipboard.getPrimaryClip();
ClipData.Item item = cdText.getItemAt(0);
//此处是TEXT文本信息
if (item.getText() != null) {
//启动手机淘宝
Intent intent = getPackageManager().getLaunchIntentForPackage("com.taobao.taobao");
startActivity(intent);
}
}
}
}
xml代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:id="@+id/card_reagents"
android:layout_width="300dp"
android:layout_height="270dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/btn_open"
android:layout_width="180dp"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp"
android:background="@drawable/bg_button"
android:text="去粘贴口令"
android:textColor="@android:color/white"
android:textSize="16sp" />
<TextView
android:id="@+id/tv_content"
android:layout_width="260dp"
android:layout_height="150dp"
android:layout_below="@+id/tv_title"
android:layout_centerHorizontal="true"
android:background="@color/bg_color"
android:text=""
android:textSize="12sp" />
<TextView
android:id="@+id/tv_title"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="口令已复制"
android:textColor="@android:color/black"
android:textSize="18sp" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
end