增加 - 服务启动验证权限

master
wangh 7 months ago
parent 91f8d10c60
commit ecdd0d15a9

@ -121,10 +121,10 @@ public class HomePageActivity extends AppCompatActivity {
}); });
binding.homeButton9.setOnClickListener(v -> { binding.homeButton9.setOnClickListener(v -> {
// 切换订单 // 切换订单
// if (!roles.contains("switch_order")) { if (!roles.contains("switch_order")) {
// Toast.makeText(this, "暂无权限", Toast.LENGTH_SHORT).show(); Toast.makeText(this, "暂无权限", Toast.LENGTH_SHORT).show();
// return; return;
// } }
intent = new Intent(this, ChangeActivity.class); intent = new Intent(this, ChangeActivity.class);
intent.putExtra("title","切换订单"); intent.putExtra("title","切换订单");
startActivity(intent); startActivity(intent);
@ -136,7 +136,11 @@ public class HomePageActivity extends AppCompatActivity {
} }
serviceIntent = new Intent(this, MyService.class); 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); user.setTeamBeens(teamBeens);
} }
}); });
getPda(); getPda();
} }
@Override @Override
@ -93,7 +89,6 @@ public class MainActivity extends BaseActivity {
if (loginState) { if (loginState) {
SharedPreferencesUtils.putstring("pdaName", pdaList.get(index).getPdaName()); SharedPreferencesUtils.putstring("pdaName", pdaList.get(index).getPdaName());
} }
} else { } else {
Toast.makeText(MainActivity.this, result.getMsg(), Toast.LENGTH_SHORT).show(); Toast.makeText(MainActivity.this, result.getMsg(), Toast.LENGTH_SHORT).show();
} }
@ -130,10 +125,10 @@ public class MainActivity extends BaseActivity {
// 登录 // 登录
public void login(View view) { public void login(View view) {
// if (!loginState) { if (!loginState) {
// Toast.makeText(this, "设备未注册,不允许登录", Toast.LENGTH_SHORT).show(); Toast.makeText(this, "设备未注册,不允许登录", Toast.LENGTH_SHORT).show();
// return; return;
// } }
String teamCode = user.getTeamCode(); String teamCode = user.getTeamCode();
if (teamCode==null||teamCode.isEmpty()) return; if (teamCode==null||teamCode.isEmpty()) return;
dialog.show(); dialog.show();
@ -143,7 +138,6 @@ public class MainActivity extends BaseActivity {
@Override @Override
public void onSuccess(Response<String> response) { public void onSuccess(Response<String> response) {
LoginBack loginBack = gson.fromJson(response.body(), LoginBack.class); LoginBack loginBack = gson.fromJson(response.body(), LoginBack.class);
if (loginBack.getCode() == 200) { if (loginBack.getCode() == 200) {
getUserInfo(loginBack.getToken()); getUserInfo(loginBack.getToken());
} else { } else {
@ -151,7 +145,6 @@ public class MainActivity extends BaseActivity {
Toast.makeText(MainActivity.this, loginBack.getMsg(), Toast.LENGTH_SHORT).show(); Toast.makeText(MainActivity.this, loginBack.getMsg(), Toast.LENGTH_SHORT).show();
} }
} }
@Override @Override
public void onError(Response<String> response) { public void onError(Response<String> response) {
super.onError(response); super.onError(response);
@ -179,6 +172,7 @@ public class MainActivity extends BaseActivity {
SharedPreferencesUtils.putstring("teamCode", user.getTeamCode()); SharedPreferencesUtils.putstring("teamCode", user.getTeamCode());
SharedPreferencesUtils.putstring("teamName", user.getTeamName()); SharedPreferencesUtils.putstring("teamName", user.getTeamName());
SharedPreferencesUtils.putstring("token", token); SharedPreferencesUtils.putstring("token", token);
intent.putExtra("userPermission", loginBack.getUserPermission());
startActivity(intent); startActivity(intent);
finish(); finish();
} else { } else {

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

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

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Loading…
Cancel
Save