[q] http get class android - Android Q&A, Help & Troubleshooting

Hi everyone,
I'm new in developing and i use android studio for developing my first apps that check if my device is rooted or not and collect information about device like( os version, manufacturer, model ).
My problem is that i need to integrating in my class that already created and successfully worked a http get request to display this information in http locally. ?
How can do this ?
pls note that i do not need anything more complex just a simple way to display the result in HTTP locally.
Thank you in advance
Regadrs
There is my class :
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
public class Sofiane_Byod_Service_activity_main extends ActionBarActivity {
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sofiane__byod__service_activity_main);
final Button button1 = (Button) findViewById(R.id.button1);
final Button button2 = (Button) findViewById(R.id.button2);
final Button button = (Button) findViewById(R.id.button);
final TextView Text1 = (TextView) findViewById(R.id.textView5);
final TextView Text2 = (TextView) findViewById(R.id.TextView09);
final TextView Text3 = (TextView) findViewById(R.id.TextView06);
final TextView Text4 = (TextView) findViewById(R.id.TextView05);
button1.setOnClickListener(new View.OnClickListener() {
@override
public void onClick(View v) {
String command[] = {"su", "-c", "ls", "/data"};
Shell_Byod shell = new Shell_Byod();
String text = shell.sendShellCommand(command);
if ((text.indexOf("app") > -1) || (text.indexOf("anr") > -1)
|| (text.indexOf("user") > -1)
|| (text.indexOf("data") > -1)) {
button2.setText("Rooted");
} else {
button2.setText("Not Rooted");
}
String curModel = Build.MODEL;
String curMan = Build.MANUFACTURER;
String curDevice = Build.DEVICE;
String curVer = Build.VERSION.RELEASE;
Text1.setText(curDevice);
Text2.setText(curModel);
Text3.setText(curMan);
Text4.setText(curVer);
}
});
}
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Related

[Q] Linking Strings between Activities and WebViews

Hello XDA,
So I've not found anyone properly discussing this. If they do, please link me to the page and don't flame
I've been making an app for my school and so far, I've been doing alright. But now I have run into a problem which seems to be very hard to solve for me alone.
Namely, I have an EditText and a Button in one Activity and a WebView as a different Activity.
I'm trying to get the EditText String into the WebView URL (String being variable, Button initiating the WebView), but get a lot of errors, some not even related to that.
I would really appreciate it if someone could have a look at the code and help me with this
MyWebView.java:
Code:
package bas.sie.Antonius;
import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MyWebView extends Activity {
WebView mWebView;
EditText mEtxtStudentNum;
static String StudentNumFromHome = bas.sie.Antonius.Home.StudentNum;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setWebViewClient(new WebViewClient());
mWebView.loadUrl("http://carmelcollegegouda.nl/site_ant/roosters/standaardroosters/Lee1_" + StudentNumFromHome + ".htm");
}
}
Home.java (Homescreen):
Code:
package bas.sie.Antonius;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class Home extends Activity {
Button mBtnStSchedule;
static EditText mEtxtStudentNum;
static final String StudentNum = mEtxtStudentNum.getText().toString();
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button next = (Button) findViewById(R.id.BtnStSchedule);
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), MyWebView.class);
startActivityForResult(myIntent, 0);
}
});
// TODO Auto-generated method stub
}
}
AntoniusActivity.java (Main):
Code:
package bas.sie.Antonius;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TabHost;
public class AntoniusActivity extends TabActivity {
WebView mWebView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, Home.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("home").setIndicator("Home",
res.getDrawable(R.drawable.ic_tab_home))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, External.class);
spec = tabHost.newTabSpec("external").setIndicator("External",
res.getDrawable(R.drawable.ic_tab_external))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, Contact.class);
spec = tabHost.newTabSpec("contact").setIndicator("Contact",
res.getDrawable(R.drawable.ic_tab_contact))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(2);
}
private class HelloWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
mWebView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
}
In AntoniusActivity, the private class HelloWebViewClient is underlined with yellow (never used), specifically the bit "HelloWebViewClient".
It's also throwing FC's at startup, and errors in LogCat, but I'll post those later on, as it's 10.30 PM here, and school goes on
Thanks in advance,
bassie1995
No suggestions yet?
How you doin'? Greetings from my GT-I9000!

[Q] Some problem with my code

Hi, I having some problem with this simple code. I don't undestrand because ADT impost fields as EditText, TextView and Button as field final. I think that there' some errore in my code, I admit that is one of my first times that i programming for andoird, so have patience with me.
I apologize if I wrong section :silly:
That's my code:
package com.example.buttoncerca;
import android.os.Bundle;
import android.app.Activity;
import android.text.Editable;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class RisponditoreInterattivoActivity extends Activity implements Lista {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_risponditore_interattivo);
final EditText text = (EditText)this.findViewById(R.id.campoNome);
Button button = (Button)this.findViewById(R.id.buttone);
final TextView tv = (TextView)this.findViewById(R.id.testoSaluto);
button.setOnClickListener(new OnClickListener(){
public void onClick(View arg0){
Editable nome = text.getText();
String s = nome.toString();
for(int c =0; c<3; c++){
if(toppings[c].equals(s)){
tv.setText(toppings[c] + " si butta nel " + cestino[c]);
} //End if
}//End for
}//End onClick
});
}
}
Click to expand...
Click to collapse
I implements inteface Lista, this is code:
package com.example.buttoncerca;
public interface Lista {
String[] toppings = {"Plastica", "Legno", "Cartone"};
String[] cestino = {"Cestino plastica", "Cestino legno", "Cestino cartone"};
}
Click to expand...
Click to collapse
And... what's the problem? Please post it "as is".
You need to instantiate the editable first, with BUFFERTYPE.EDITABLE, because in your current case you are casting a charseq to an editable so that's likely the exception you are getting (hard to know without a logcat). See here:
http://developer.android.com/reference/android/widget/EditText.html#getText()
Sent from my Amaze 4G using xda app-developers app

[Q] Android problem in scaling and transformation

When the user touches a view i need to scale that view and show that scaled view of that point in a circle as shown in the image .But when i am using matrix and do scaling instead of touch point area i am getting other one .The question is how do i calculate a same point after scaling on scaled view.
Please see the attached images and guide me where i am going wrong if there is a better solution please provide me.
The car image is target and the wall image is my work i must implement the same zooming here
My code
Code:
import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Shader.TileMode;
import android.os.Environment;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;
public class PaintView extends ImageView {
public static ArrayList<Float> xPoints;
public static ArrayList<Float> yPoints;
private Canvas mCanvas;
public static Path mPath;
public static Path mPath1;
public static Path mPath2;
public static Path mPath3;
public static Path mPath4;
Context mContext;
private Paint mPaint = new Paint();
private Paint pPaint = new Paint();
boolean isEndReached;
public static float startX, startY, prevX, prevY;
long prevTime;
Timer t;
TimerTask task;
Context mcontext;
private float mX, mY;
float prevCX = 0f;
float prevCY = 0f;
public static ArrayList<android.graphics.Point> points, points1, points2,
points3, points4;
private static final float TOUCH_TOLERANCE = 4;
public static ArrayList<Point> pointArray, pointArray1, pointArray2,
pointArray3, pointArray4;
private Bitmap bmp;
private BitmapShader shader;
private Matrix matrix = new Matrix();;
private Paint shaderPaint;
PointF zoomPos;
PointF mid = new PointF();
PointF start = new PointF();
boolean isDrawingStarted;
//RectF rect;
public PaintView(Context context, AttributeSet attrs) {
super(context, attrs);
mcontext = context;
String filePath = Environment.getExternalStorageDirectory()
+ "/test.png";
BitmapFactory.Options options = new BitmapFactory.Options();
//options.inPurgeable = true;
bmp = BitmapFactory.decodeFile(filePath, options);
AppUtils.LOG("------ bitmap ------- " + bmp);
bmp = Bitmap.createScaledBitmap(bmp, AppUtils.IMG_WIDTH,
AppUtils.IMG_HEIGHT, true);
zoomPos = new PointF();
shader = new BitmapShader(bmp, TileMode.CLAMP, TileMode.CLAMP);
shaderPaint = new Paint();
shaderPaint.setShader(shader);
}
[user=439709]@override[/user]
public boolean onTouchEvent(MotionEvent event) {
float x = event.getX();
float y = event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
touch_start(x, y);
if (t != null) {
t.cancel();
}
zoomPos.x = event.getX();
zoomPos.y = event.getY();
matrix.reset();
matrix.postScale(1.5f, 1.5f, zoomPos.x, zoomPos.y);
shader.setLocalMatrix(matrix);
invalidate();
break;
case MotionEvent.ACTION_MOVE:
touch_move(x, y);
zoomPos.x = event.getX();
zoomPos.y = event.getY();
matrix.reset();
matrix.postScale(1.5f, 1.5f, zoomPos.x, zoomPos.y);
shader.setLocalMatrix(matrix);
invalidate();
break;
case MotionEvent.ACTION_UP:
touch_up(x, y);
reScheduleTimer();
invalidate();
break;
case MotionEvent.ACTION_POINTER_DOWN:
midPoint(mid, event);
invalidate();
break;
}
this.setImageMatrix(matrix);
return true;
}
[user=439709]@override[/user]
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (isDrawingStarted) {
canvas.drawCircle(zoomPos.x, zoomPos.y, 110, shaderPaint);
}
}
}

Calling a fragment from another list type ListFragment

Hello everyone wanted to know if I can support, I have a project in which I have implemented a tablayout with 3 tabs, each tabs I have assigned a fragment, for the first tab I have a listfragment and show the list correctly, but selecting an element of the list want the switch to another fragment that will also display another list.
For example I have a list of categories, in the fragment of listfragment type in the first tab, but selecting an item from the list I want to show the items child of that category in another list, but in the same tab, reached the code, as managing that change, ie another fragment listfragment call type from listfragment.
File: TabCategoriasFragment.java
Code:
package com.gydsoluciones.grva.recetasperu;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.ListFragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.VolleyLog;
import com.android.volley.toolbox.JsonArrayRequest;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
/**
* Created by grva on 20/05/2016.
*/
public class TabCategoriasFragment extends ListFragment{
String[] categorias = {"Licores","Sopas","Pescados y Mariscos","Arroces","Ensaladas","Repostería","Salsas"};
Integer[] pics = {R.drawable.licores,R.drawable.sopas,R.drawable.pescadosmariscos,R.drawable.arroces,R.drawable.ensaladas,R.drawable.reposteria,R.drawable.salsas};
String[] descripcion = {
"Los mejores licores","Selección de las mejores sopas y caldos",
"Los mejores platos a base de pescados y mariscos","Arroz con pollo, Arroz chaufa, entre otros",
"Las mejores ensaladas frescas","Lo mejor para endulzar el momento","Las mejores salsas basadas en la variedad peruana"
};
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
CategriaListAdapter adapter = new CategriaListAdapter(getActivity(),categorias,pics,descripcion);
setListAdapter(adapter);
return inflater.inflate(R.layout.lista_categorias,container,false);
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
String itemText = categorias[+position];
String url = "url web service";
ProgressDialog pDialog = new ProgressDialog(getContext());
pDialog.setMessage("Cargando...");
pDialog.show();
final JsonArrayRequest req = new JsonArrayRequest(url, new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
Log.d("json_array_req",response.toString());
try {
String[] recetas = new String[response.length()];
for (int i = 0; i < response.length(); i++) {
JSONObject receta = (JSONObject) response.get(i);
recetas[i] = receta.getString("titurece");
}
}catch(JSONException e)
{
Log.d("json_array_req", e.toString());
}
}
},new Response.ErrorListener(){
@Override
public void onErrorResponse(VolleyError error){
VolleyLog.d("json_array_req","Error:" + error.getMessage());
}
});
AppController.getInstance().addToRequestQueue(req,"json_array_req");
pDialog.hide();
}
}

marker not display on googlemap

package com.example.sameer.vehicletrackingsystem.Fragments;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.example.sameer.vehicletrackingsystem.R;
import com.google.android.gms.maps.*;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
public class GoogleMapFragment extends Fragment implements OnMapReadyCallback {
private GoogleMap mMap;
String add = "Mandhardev";
String state = "Maharashtra";
String country = "India";
String vehicleNumber = "MH-12 FG-1547";
public GoogleMapFragment() {
// Required empty public constructor
}
@override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_google_map, container, false);
}
@override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.addMarker(new MarkerOptions().position(new LatLng(18.046644, 73.876045)).title(vehicleNumber).snippet(add+", "+state+", "+country));
mMap.getMaxZoomLevel();
mMap.getCameraPosition();
}
}

Categories

Resources