Search the Community
Showing results for tags 'android studio'.
-
Estou a muito pouco tempo a trabalhar em java. Preciso de fazer a assinatura digital em documentos para serem incluídos no saft e não estou a conseguir. Tenho o problemas das guias de transporte e assinatura de documentos resolvido em vb.net, se alguém precisar é só dizer. Fiz isto mas não saio daqui.. Obrigado... private void Assinar_Documento() { String FASE="1"; String Assinatura="2010-05-18;2010-05-18T11:22:19;FAC 001/14;3.12;"; String privateKeyString = ""+ //-----BEGIN RSA PRIVATE KEY-----\n"+ "---------------------------------------------------------------+\n" + "---------------------------------------------------------------+\n" + "---------------------------------------------------------------+\n" + "---------------------------------------------------------------+\n" + "---------------------------------------------------------------+\n" + "---------------------------------------------------------------+\n" + "---------------------------------------------------------------+\n" + "---------------------------------------------------------------+\n" + "---------------------------------------------------------------+\n" + "---------------------------------------------------------------+\n" + "---------------------------------------------------------------+\n" + "-----------------------------------"; //"-----END RSA PRIVATE KEY-----"; try { //PrivateKey key = getPrivateKey(privateKeyString); KeyFactory kf = KeyFactory.getInstance("RSA"); PKCS8EncodedKeySpec keySpecPKCS8 = new PKCS8EncodedKeySpec(Base64.decode(privateKeyString,Base64.DEFAULT)); PrivateKey key = kf.generatePrivate(keySpecPKCS8); byte[] message = Assinatura.getBytes(StandardCharsets.UTF_8); byte[] signature = rsaSign(message,key); FASE="2"; String Ass = new String(signature, StandardCharsets.UTF_8); Msg_Info("LEN="+Ass.length(),Ass); } catch (Exception Erro){ Msg_Error(FASE,Erro.getMessage()); } } public byte[] rsaSign (byte[] data,PrivateKey key) { byte[] cipherData = null; try { Signature s = Signature.getInstance("SHA1withRSA"); s.initSign(key); s.update(data); Log.e("s.sign()", Base64.encodeToString(s.sign(), Base64.DEFAULT)); return s.sign(); } catch (Exception e) { Msg_Error("ERRO",e.getMessage()); } return cipherData; } public PrivateKey getPrivateKey(String key) { PrivateKey privateKey = null; try { String privateString = key; if(privateString!=null){ byte[] binCpk = Base64.decode(privateString,Base64.DEFAULT); KeyFactory keyFactory = KeyFactory.getInstance("RSA"); PKCS8EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(binCpk); privateKey = keyFactory.generatePrivate(privateKeySpec); } } catch(Exception e){ } return privateKey; }
-
public class PrincipalActivity extends AppCompatActivity { private RecyclerView recyclerView; private List<MenuVertical> postagens = new ArrayList<>(); @SuppressLint("WrongConstant") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_principal); recyclerView = findViewById(R.id.recyclerView); //Define layout LinearLayoutManager layoutManager = new LinearLayoutManager(this); layoutManager.setOrientation(LinearLayout.VERTICAL); //RecyclerView.LayoutManager layoutManager = new GridLayoutManager(this, 2); recyclerView.setLayoutManager(layoutManager); //Define adapter this.criarListagem(); Adapter adapter = new Adapter(postagens); recyclerView.setAdapter(adapter); } public void criarListagem() { MenuVertical p = new MenuVertical("Émerson Henrique", "Aqui ficam os Textos", R.drawable.miami, "Alguns eu escrevi e outros eu achei que devia colocar"); this.postagens.add(p); p = new MenuVertical("Usuário Henrique", "Aqui ficam algumas músicas", R.drawable.musica, "Musicas Selecionas por mim"); this.postagens.add(p); p = new MenuVertical("Usuário Émerson", "logo em breve vou fazer mais", R.drawable.manutencao, "Em manutenção"); this.postagens.add(p); } } public class Adapter extends RecyclerView.Adapter { private List<MenuVertical> postagens; public Adapter(List<MenuVertical> listaPostagens) { this.postagens = listaPostagens; } @NonNull @Override public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { // tranformar o adapter xml em item view View itemLista = LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_lista_vertical, parent, false); return new MyViewHolder(itemLista); } @Override public void onBindViewHolder(@NonNull MyViewHolder holder, int position) { MenuVertical postagem = postagens.get(position); holder.nome.setText(postagem.getNome()); holder.subTitulo.setText(postagem.getSubTitulo()); holder.imagePostagem.setImageResource(postagem.getImagem()); holder.descricao.setText(postagem.getDescricao()); //holder.buttonProx.setOnClickListener((View.OnClickListener) postagem.getButtonProx()); //holder.genero.setText(filme.getGenero()); //holder.ano.setText(filme.getAno()); } @Override public int getItemCount() { return postagens.size(); } public class MyViewHolder extends RecyclerView.ViewHolder { private TextView nome; private TextView subTitulo; private ImageView imagePostagem; private TextView descricao; //Button buttonProx; public MyViewHolder(@NonNull View itemView) { super(itemView); nome = itemView.findViewById(R.id.textNome); subTitulo = itemView.findViewById(R.id.textSubTitulo); imagePostagem = itemView.findViewById(R.id.imagePostagem); descricao = itemView.findViewById(R.id.textDescricao); // buttonProx = itemView.findViewById(R.id.buttonProx); } } }
- 1 reply
-
- android
- android studio
-
(and 2 more)
Tagged with:
-
Pessoal, com o código abaixo eu populo um Spiiner; Esse Spinner, é populado por um atributo de um Array de objetos À principio, temos o seguinte JSONArray: [ { "id":"1", "nome":"Carlos" }, { "id":"2", "nome":"Cleonice Rocha" }, { "id":"3", "nome":"Cleonice Rocha" } ] Agora temos o método: private void preencheComboClientes(JSONArray jsClientes) throws JSONException { JSONObject jsonObject; final HashMap<Integer, String> listaClientes = new HashMap<Integer, String>(); for (Integer i = 0; i < jsClientes.length(); i++) { jsonObject = jsClientes.getJSONObject(i).getJSONObject("cliente"); Integer id = jsonObject.getInt("id"); String nome = jsonObject.getString("nome"); listaClientes.put(id, nome); } List<StringWithTag> itemList = new ArrayList<StringWithTag>(); for (Map.Entry<Integer, String> entry : listaClientes.entrySet()) { Integer key = entry.getKey(); String value = entry.getValue(); itemList.add(new StringWithTag(value, key)); } spinnerAdapterClientes = new ArrayAdapter<StringWithTag>(this, android.R.layout.simple_spinner_item, itemList); spinnerAdapterClientes.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spCliente.setAdapter(spinnerAdapterClientes); spCliente.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { for (Map.Entry<Integer, String> entry : listaClientes.entrySet()) { Integer key = entry.getKey(); String value = entry.getValue(); if (parent.getSelectedItem().toString().equals(value)) { Log.i("Achei!!!" , Integer.toString(key)); } } } @Override public void onNothingSelected(AdapterView<?> parent) { // sometimes you need nothing here } }); } Então, imagine a situação em que você tem um Array de Objetos e esse Objeto possui CPF e NOME Bom, CPF cada um tem o seu. Não se repete. Mas, Nome, infelizmente podemos ter 2 nomes iguais Logo, não posso enviar a consulta por nome e sim por CPF Como o Spinner não aceita CPF e Nome, logo, fico impossibilitado de fazer conferências. Como vocês fazer nesse caso?
-
Tenho a seguinte saída JSON vinda de uma API: { "status":"ok", "equipamentos": [ { "equipamento": "{ \"id\":7, \"cliente\":1, \"tipo\":\"Celular\", \"marca\":\"Motorola\", \"modelo\":\"Moto G 7\", \"serial\":\"Aparelho n\\u00e3o liga\", \"caracteristicas\":\"P\\u00c9SSIMO\" }" }, { "equipamento": "{ \"id\":8, \"cliente\":1, \"tipo\":\"Celular\", \"marca\":\"Motorola\", \"modelo\":\"Moto G 7\", \"serial\":\"Aparelho n\\u00e3o liga\", \"caracteristicas\":\"P\\u00c9SSIMO\" }" } ] } E o seguinte método para gerar um novo objeto à partir do índice "equipamentos" gerado do JSON recebido da API @Override protected void onPostExecute(String str) { progressDialog.cancel(); JSONObject retorno = null; try { retorno = new JSONObject(str); if ( retorno.has("equipamentos")) preencherComboEquipamentos(retorno.getJSONObject("equipamentos")); } catch (JSONException e) { e.printStackTrace(); } } Com ele, o método preencherComboEquipamentos receberá um objeto como abaixo: [ { "equipamento": "{ \"id\":7, \"cliente\":1, \"tipo\":\"Celular\", \"marca\":\"Motorola\", \"modelo\":\"Moto G 7\", \"serial\":\"Aparelho n\\u00e3o liga\", \"caracteristicas\":\"P\\u00c9SSIMO\" }" }, { "equipamento": "{ \"id\":8, \"cliente\":1, \"tipo\":\"Celular\", \"marca\":\"Motorola\", \"modelo\":\"Moto G 7\", \"serial\":\"Aparelho n\\u00e3o liga\", \"caracteristicas\":\"P\\u00c9SSIMO\" }" } ] Agora preciso criar um JSONArray de JSONObjects com apenas 2 campos trazidos do JSONObject anterior que são id e cliente. Estou tentando assim mas não está dando certo private void preencheComboClientes(JSONObject JSClientes) throws JSONException { JSONObject clientes = null; ArrayList<JSONObject> clientesList = null; for (int i = 0; i < JSClientes.length(); i++) { clientes.put("id", JSClientes.getJSONObject(i).getInt("id")); clientes.put("nome", JSClientes.getJSONObject(i).getInt("nome")); clientesList[clientes]; } ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, clientes); spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spCliente.setAdapter(spinnerArrayAdapter); } A ideia é preencher um spinner.
-
Boa tarde estou com um grave problema porque não sei como hei de enviar a longitude e latitude obtida a partir do meu smartphone de uma app que desonvolvi no android studio e receba esses dados no meu servidor para inserir na base de dados mysql....