增加 - 服务启动验证权限

master
wangh 7 months ago
parent 91f8d10c60
commit ecdd0d15a9

@ -121,10 +121,10 @@ public class HomePageActivity extends AppCompatActivity {
});
binding.homeButton9.setOnClickListener(v -> {
// 切换订单
// if (!roles.contains("switch_order")) {
// Toast.makeText(this, "暂无权限", Toast.LENGTH_SHORT).show();
// return;
// }
if (!roles.contains("switch_order")) {
Toast.makeText(this, "暂无权限", Toast.LENGTH_SHORT).show();
return;
}
intent = new Intent(this, ChangeActivity.class);
intent.putExtra("title","切换订单");
startActivity(intent);
@ -136,7 +136,11 @@ public class HomePageActivity extends AppCompatActivity {
}
serviceIntent = new Intent(this, MyService.class);
startService(serviceIntent);
var userPermission = intent1.getIntExtra("userPermission", 0);
if (userPermission==2){
startService(serviceIntent);
}
}

@ -61,11 +61,7 @@ public class MainActivity extends BaseActivity {
user.setTeamBeens(teamBeens);
}
});
getPda();
}
@Override
@ -93,7 +89,6 @@ public class MainActivity extends BaseActivity {
if (loginState) {
SharedPreferencesUtils.putstring("pdaName", pdaList.get(index).getPdaName());
}
} else {
Toast.makeText(MainActivity.this, result.getMsg(), Toast.LENGTH_SHORT).show();
}
@ -130,10 +125,10 @@ public class MainActivity extends BaseActivity {
// 登录
public void login(View view) {
// if (!loginState) {
// Toast.makeText(this, "设备未注册,不允许登录", Toast.LENGTH_SHORT).show();
// return;
// }
if (!loginState) {
Toast.makeText(this, "设备未注册,不允许登录", Toast.LENGTH_SHORT).show();
return;
}
String teamCode = user.getTeamCode();
if (teamCode==null||teamCode.isEmpty()) return;
dialog.show();
@ -143,7 +138,6 @@ public class MainActivity extends BaseActivity {
@Override
public void onSuccess(Response<String> response) {
LoginBack loginBack = gson.fromJson(response.body(), LoginBack.class);
if (loginBack.getCode() == 200) {
getUserInfo(loginBack.getToken());
} else {
@ -151,7 +145,6 @@ public class MainActivity extends BaseActivity {
Toast.makeText(MainActivity.this, loginBack.getMsg(), Toast.LENGTH_SHORT).show();
}
}
@Override
public void onError(Response<String> response) {
super.onError(response);
@ -179,6 +172,7 @@ public class MainActivity extends BaseActivity {
SharedPreferencesUtils.putstring("teamCode", user.getTeamCode());
SharedPreferencesUtils.putstring("teamName", user.getTeamName());
SharedPreferencesUtils.putstring("token", token);
intent.putExtra("userPermission", loginBack.getUserPermission());
startActivity(intent);
finish();
} else {

@ -26,8 +26,8 @@ import okhttp3.MediaType;
public abstract class BaseActivity extends AppCompatActivity {
private MyBroad receiver;
public static String url="http://192.168.137.1:8080";
// public static String url="http://10.100.72.10:8080";
// public static String url="http://192.168.137.1:8080";
public static String url = "http://10.100.72.10:8080";
public ProgressDialog dialog;
public Gson gson;
public MediaType JSON = MediaType.parse("application/json; charset=utf-8");
@ -56,7 +56,9 @@ public abstract class BaseActivity extends AppCompatActivity {
public void goodsNameCall(String code) {
}
private String codeTag = "";
public void selectGoodsName(String code) {
if (codeTag.equals(code)) return;
codeTag = code;
@ -64,21 +66,22 @@ public abstract class BaseActivity extends AppCompatActivity {
.tag(this)
.headers("Authorization", SharedPreferencesUtils.getstring("token", ""))
.params("code", code)
.execute(new MyRecultCall(dialog,this){
.execute(new MyRecultCall(dialog, this) {
@Override
public void onSuccess(Response<Result> response) {
super.onSuccess(response);
Result result = response.body();
if (result.getCode()==200){
if (result.getCode() == 200) {
Toast.makeText(BaseActivity.this, "查询成功", Toast.LENGTH_SHORT).show();
goodsNameCall(result.getData().toString()) ;
}else {
goodsNameCall(result.getData().toString());
} else {
Toast.makeText(BaseActivity.this, result.getMsg(), Toast.LENGTH_SHORT).show();
goodsNameCall(null) ;
goodsNameCall(null);
}
}
});
}
@Override
protected void onDestroy() {
super.onDestroy();

@ -12,6 +12,15 @@ public class LoginBack {
private int code;
private String token;
private ArrayList<String> roles;
private int userPermission;
public int getUserPermission() {
return userPermission;
}
public void setUserPermission(int userPermission) {
this.userPermission = userPermission;
}
public ArrayList<String> getRoles() {
return roles;

@ -37,7 +37,6 @@ public class MyService extends Service {
public int onStartCommand(Intent intent, int flags, int startId) {
Log.e("TAG", "服务启动");
startQuery();
return START_STICKY;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Loading…
Cancel
Save