赞
踩
回调结果:
implementation 'com.github.goweii:AnyPermission:1.1.2'
implementation 'com.github.goweii:AnyLayer:v2.2.0'
private void requestNotificationShow() { Log.e(TAG, "requestNotificationShow: =================================" ); AnyPermission.with(mWXSDKInstance.getContext()).notificationShow() .onWithoutPermission(new RequestInterceptor<Void>() { @Override public void intercept(@NonNull Void data, @NonNull final Executor executor) { // processor有两个方法,必须调用其一,否则申请流程将终止。 Log.e("TAG", "intercept:=========== " ); AnyLayer.with(mWXSDKInstance.getContext()) .contentView(R.layout.dialog_runtime_before_request) .backgroundColorRes(R.color.dialog_bg) .cancelableOnTouchOutside(false) .cancelableOnClickKeyBack(false) .bindData(new AnyLayer.IDataBinder() { @Override public void bind(AnyLayer anyLayer) { final TextView tvTitle = anyLayer.getView(R.id.tv_dialog_permission_title); final TextView tvDescription = anyLayer.getView(R.id.tv_dialog_permission_description); final TextView tvNext = anyLayer.getView(R.id.tv_dialog_permission_next); tvTitle.setText("显示通知"); tvNext.setText("去打开"); tvDescription.setText("我们将开始请求显示通知权限"); } }) .onClickToDismiss(new AnyLayer.OnLayerClickListener() { @Override public void onClick(AnyLayer anyLayer, View v) { executor.execute(); } }, R.id.tv_dialog_permission_next) .onClickToDismiss(new AnyLayer.OnLayerClickListener() { @Override public void onClick(AnyLayer anyLayer, View v) { executor.cancel(); } }, R.id.tv_dialog_permission_close) .show(); } }) .request(new RequestListener() { @Override public void onSuccess() { // TODO 授权成功 Log.e("TAG", "onSuccess: " ); } @Override public void onFailed() { // TODO 授权失败 Log.e("TAG", "onFailed: " ); } }); }
@JSMethod(uiThread = true)
public void startMyService(){
((Activity) mWXSDKInstance.getContext()).runOnUiThread(new Runnable() {
@Override
public void run() {
//此时已在主线程中,可以更新UI了
requestNotificationShow();
}
});
}
这样就可以动态申请通知权限了。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。