Android跳转微信小程序
添加依赖
在build.gradle文件中,添加如下依赖:
dependencies {
implementation 'com.tencent.mm.opensdk:wechat-sdk-android-with-mta:5.3.1'
}
导入class
import com.tencent.mm.opensdk.modelbiz.WXLaunchMiniProgram;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
申请移动应用记录其应用ID
申请时需要应用logo 2828 108108 两个尺寸
签名生成工具
用于获取安装到手机的第三方应用签名的apk包,由com.xxx.xxx生成。
点击下载 签名生成工具
绑定小程序 记录其原始ID
按键跳转
String appId = "wx097c72f6bdbxxxxx"; // 填应用AppId
IWXAPI api = WXAPIFactory.createWXAPI(this, appId);
WXLaunchMiniProgram.Req req = new WXLaunchMiniProgram.Req();
req.userName = "gh_0861359xxxxx"; // 填小程序原始idthis
req.path = path; //拉起小程序页面的可带参路径,不填默认拉起小程序首页
req.miniprogramType = WXLaunchMiniProgram.Req.MINIPTOGRAM_TYPE_RELEASE;// 可选打开 开发版,体验版和正式版
api.sendReq(req);
Android 跳转到其他APP
Intent intent = getPackageManager().getLaunchIntentForPackage("com.aispeech.companionapp");
if (intent != null) {
intent.putExtra("type", "110"); //带参数的跳转
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
Android activity之间传参
发送端
Intent intent = new Intent(SoundSearchActivity.this,SoundInputWifiActivity.class);
Bundle bundle = new Bundle();
bundle.putParcelable("user", device);
intent.putExtras(bundle);
mDeviceScanner.stopScan();
startActivity(intent);
接收端
Intent intent = this.getIntent();
bluetooth_device=(BluetoothDevice)intent.getParcelableExtra("user");
ToastUtils.show(bluetooth_device.getName());
Android imageview 缩放动画
先创建一个scale.xml
<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2000"
android:fillAfter="true"
android:fillBefore="true"
android:fromXScale="0.5"
android:fromYScale="0.5"
android:interpolator="@android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="-1"
android:repeatMode="reverse"
android:startOffset="50"
android:toXScale="4.0"
android:toYScale="4.0"/>
再到activity里面
@SuppressLint("ResourceType") ScaleAnimation scaleAnimation = (ScaleAnimation) AnimationUtils.loadAnimation(this, R.xml.scale);
ImageView move_img.startAnimation(scaleAnimation);
Android 保存本地变量
保存数据
private SharedPreferences.Editor editor;
private SharedPreferences preferences;
editor.putString("ip",set_ip);
editor.commit();
获取数据
editor = getSharedPreferences("data",MODE_PRIVATE).edit();
preferences = getSharedPreferences("data",MODE_PRIVATE);
手动添加申请获取手机号 MAC IMEI信息权限
new RxPermissions(this).request(Manifest.permission.READ_PHONE_STATE).subscribe(new Consumer<Boolean>() {
@Override
public void accept(Boolean aBoolean) throws Exception {
if (aBoolean) {
initUpdate();
if (LocationUtil.isOpenLocation(HomeActivity.this)) {
startLBS();
}
SwitchManager.getInstance().init();
}
}
});