List of usage examples for android.os StrictMode setThreadPolicy
public static void setThreadPolicy(final ThreadPolicy policy)
From source file:com.sourcey.materiallogindemo.PostItemActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_postlist); // Permission StrictMode if (Build.VERSION.SDK_INT > 9) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); }//w w w. j a v a 2 s . c o m Bundle extras = getIntent().getExtras(); // ?? null if (extras != null) { user_id = extras.getString("user_id"); name = extras.getString("name"); image = extras.getString("image"); } final Button btnPost = (Button) findViewById(R.id.btnPost); // final Button btnFeed = (Button) findViewById(R.id.btnFeed); final Button btnNotification = (Button) findViewById(R.id.btnNotification); final Button btnComment = (Button) findViewById(R.id.btnComment); final Button btnLogout = (Button) findViewById(R.id.btnLogout); radioGroup = (RadioGroup) findViewById(R.id.radio); listView = (ListView) this.findViewById(R.id.postListView); badge = (TextView) findViewById(R.id.badge); this.generateDummyData(); this.ConutNotification(); radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { // find the radiobutton by returned id type = ((RadioButton) findViewById(radioGroup.getCheckedRadioButtonId())).getText().toString(); if ("".equals(type)) { type = "CAR"; } else { type = "NOCAR"; } generateDummyData(); } }); btnPost.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent i = new Intent(getBaseContext(), MainActivity.class); i.putExtra("user_id", user_id); i.putExtra("name", name); i.putExtra("image", image); startActivity(i); } }); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String map_id = listData[position].postMapID; String passenger = listData[position].user_id; strStart = listData[position].postStart.replace(": ", ""); strEnd = listData[position].postEnd.replace(": ", ""); DialogRequest(map_id, passenger); } }); btnNotification.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(getBaseContext(), NotificationActivity.class); i.putExtra("user_id", user_id); i.putExtra("name", name); i.putExtra("image", image); startActivity(i); } }); btnLogout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(getBaseContext(), LoginActivity.class); startActivity(i); } }); btnComment.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(getBaseContext(), CommentActivity.class); i.putExtra("user_id", user_id); i.putExtra("name", name); i.putExtra("image", image); startActivity(i); } }); }
From source file:com.project.utilities.Utilities.java
/** * Sends get request to sepcified URL.//from w ww.ja v a 2 s. c om * @param getUri * @return */ public static String getRequest(final String getUrl) { String responseStr = null; StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); HttpClient httpclient = new DefaultHttpClient(); Log.e("GET_REQUEST", "ACTION REQUEST"); try { // Execute HTTP Post Request HttpGet request = new HttpGet(); request.setURI(new URI(getUrl)); HttpResponse response = httpclient.execute(request); response.getStatusLine().getStatusCode(); BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuffer sb = new StringBuffer(""); String l = ""; String nl = System.getProperty("line.separator"); while ((l = in.readLine()) != null) { sb.append(l + nl); } in.close(); responseStr = sb.toString(); Log.e("POST_REQUEST", "RESPONSE_STR: " + responseStr); Log.e("POST_REQUEST", "RESPONSE_CODE: " + response.getStatusLine().getStatusCode() + ""); } catch (ClientProtocolException e) { Log.e("ClientProtocolException", e.getMessage().toString()); } catch (IOException e) { Log.e("IOException", e.getMessage().toString()); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } return responseStr; }
From source file:com.sourcey.materiallogindemo.NotificationActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_nontification); // Permission StrictMode if (Build.VERSION.SDK_INT > 9) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); }// ww w .j a va 2s .co m Bundle extras = getIntent().getExtras(); // ?? null if (extras != null) { user_id = extras.getString("user_id"); name = extras.getString("name"); image = extras.getString("image"); } final Button btnPost = (Button) findViewById(R.id.btnPost); final Button btnFeed = (Button) findViewById(R.id.btnFeed); final Button btnLogout = (Button) findViewById(R.id.btnLogout); final Button btnComment = (Button) findViewById(R.id.btnComment); listView = (ListView) this.findViewById(R.id.postListView); badge = (TextView) findViewById(R.id.badge); this.generateDummyData(); this.ConutNotification(); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { request_id = listData[position].request_id; map_id = listData[position].postMapID; r_user_id = listData[position].r_user_id; r_type = listData[position].type; DialogConfirmRequest(); } }); btnPost.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent i = new Intent(getBaseContext(), MainActivity.class); i.putExtra("user_id", user_id); i.putExtra("name", name); i.putExtra("image", image); startActivity(i); } }); btnFeed.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent i = new Intent(getBaseContext(), PostItemActivity.class); i.putExtra("user_id", user_id); i.putExtra("name", name); i.putExtra("image", image); startActivity(i); } }); btnLogout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(getBaseContext(), LoginActivity.class); startActivity(i); } }); btnComment.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(getBaseContext(), CommentActivity.class); i.putExtra("user_id", user_id); i.putExtra("name", name); i.putExtra("image", image); startActivity(i); } }); }
From source file:com.melchor629.musicote.Utils.java
/** * HostTest/* w ww . j a v a2s. com*/ * Sirve para comprobar si est encendido el PC * Nothing to see here... * * @param host HOST IP * @return int response */ public static int HostTest(String host) { int response = 0; try { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); URL urlhttp = new URL("http://" + host); HttpURLConnection http = (HttpURLConnection) urlhttp.openConnection(); http.setReadTimeout(1000); response = http.getResponseCode(); http.disconnect(); } catch (Exception e) { Log.e("Comprobando", "Excepcin HTTPURL: " + e.toString() + " " + host); } return response; }
From source file:com.example.team04adventure.Model.JSONparser.java
public JSONparser() { this.gson = new Gson(); StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); }
From source file:com.example.karspoolingapp.RouteByHitchhikerCar.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.routebyhitchhiker); Intent intent = getIntent();//from www. ja va 2s . co m Bundle bundle = intent.getExtras(); new_license_number = bundle.getString("pre_end_point"); //session_username = session.getUsername(); System.out.println("nayaaa licnse number" + new_license_number); StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); // code for dynamic radio button generation final RadioButton[] rb = new RadioButton[100]; rl = (RelativeLayout) findViewById(R.id.rl); rg = new RadioGroup(this); // Building Parameters List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("car_number", new_license_number)); System.out.println(params); json = jsonParser.makeHttpRequest(READ_COMMENTS_URL2, "POST", params); params.clear(); System.out.println(json); try { jsonTripDetails = json.getJSONArray("route"); System.out.println(jsonTripDetails); int k = jsonTripDetails.length(); if (k > 0) { for (int i = 0; i < jsonTripDetails.length(); i++) { JSONObject c = jsonTripDetails.getJSONObject(i); String parent_username_str = c.getString("username"); String route = c.getString("route"); String timing = c.getString("timing"); String seating = c.getString("seating_capacity"); rb[i] = new RadioButton(this); rg.addView(rb[i]); rb[i].setText(parent_username_str + "," + route + "," + timing + "," + seating); params.clear(); } rl.addView(rg); rl.setPadding(50, 50, 50, 50); } else { Toast.makeText(RouteByHitchhikerCar.this, "No Trip available on these routes", Toast.LENGTH_LONG) .show(); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } addListenerOnButton(); }
From source file:utkarsh.com.warrantywallet.activities.MainActivity.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override//www .j a va 2 s .co m protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (android.os.Build.VERSION.SDK_INT > 9) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); } Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); mFragmentManager = getSupportFragmentManager(); auth = FirebaseAuth.getInstance(); mFirebaseAnalytics = FirebaseAnalytics.getInstance(this); //get current user final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); System.out.println("MainActivity.onCreate: " + user.getDisplayName()); System.out.println("MainActivity.onCreate: " + user.getEmail()); System.out.println("MainActivity.onCreate: " + user.getProviderId()); System.out.println("MainActivity.onCreate: " + user.getUid()); System.out.println("MainActivity.onCreate: " + user.getPhotoUrl()); System.out.println("MainActivity.onCreate: " + user.getProviders()); System.out.println("MainActivity.onCreate: " + user.getProviderData().get(0)); System.out.println("MainActivity.onCreate: " + user.getToken(true)); authListener = new FirebaseAuth.AuthStateListener() { @Override public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { // FirebaseUser user = firebaseAuth.getCurrentUser(); if (user == null) { // user auth state is changed - user is null // launch login activity startActivity(new Intent(MainActivity.this, LoginActivity.class)); finish(); } } }; mFirebaseAnalytics.setUserProperty("favorite_food", "set your data here"); // set property to save data in analysis logAnalysisEvents(); //set events to be logged FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { startActivity(new Intent(MainActivity.this, NewPostActivity.class)); /* Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) .setAction("Action", null).show();*/ } }); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); }
From source file:org.kaaproject.kaa.demo.notification.activity.MainActivity.java
private void permitPolicy() { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); }
From source file:com.brodev.socialapp.view.VideoPlay.java
/** Called when the activity is first created. */ @Override//www . j a va 2 s . c om public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.video_player); if (android.os.Build.VERSION.SDK_INT > 9) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); } getSupportActionBar().setDisplayHomeAsUpEnabled(true); user = (User) getApplication().getApplicationContext(); phraseManager = new PhraseManager(getApplicationContext()); colorView = new ColorView(getApplicationContext()); Bundle bundle = getIntent().getExtras(); video = (Video) bundle.get("video"); getSupportActionBar().setTitle(phraseManager.getPhrase(getApplicationContext(), "video.video")); if (video.getTime_stamp().equals("0")) { this.getVideoAdapter(); } initView(); // get comment fragment Bundle comment = new Bundle(); comment.putString("type", "video"); comment.putInt("itemId", video.getVideo_id()); comment.putInt("totalComment", video.getTotal_comment()); comment.putInt("total_like", video.getTotal_like()); comment.putBoolean("is_liked", video.getIs_like()); comment.putBoolean("can_post_comment", video.getCan_post_comment()); CommentFragment commentFragment = new CommentFragment(); commentFragment.setArguments(comment); getSupportFragmentManager().beginTransaction().add(R.id.commentfragment_wrap, commentFragment).commit(); }
From source file:com.vishnuvalleru.travelweatheralertsystem.MainActivity.java
@SuppressLint("NewApi") @Override//from w ww .ja v a2 s . com protected void onCreate(Bundle savedInstanceState) { Bundle b = getIntent().getExtras(); String fromLocation = b.getString("from"); String toLocation = b.getString("to"); Geocoder coder = new Geocoder(this); StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); try { ArrayList<Address> frmAddresses = (ArrayList<Address>) coder.getFromLocationName(fromLocation, 50); ArrayList<Address> toAddresses = (ArrayList<Address>) coder.getFromLocationName(toLocation, 50); for (Address add : frmAddresses) { src_long = add.getLongitude(); src_lat = add.getLatitude(); } for (Address add : toAddresses) { dest_long = add.getLongitude(); dest_lat = add.getLatitude(); } } catch (IOException e) { e.printStackTrace(); } LatLng srcLatLng = new LatLng(src_lat, src_long); LatLng destLatLng = new LatLng(dest_lat, dest_long); super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); FragmentManager myFragmentManager = getFragmentManager(); MapFragment myMapFragment = (MapFragment) myFragmentManager.findFragmentById(R.id.map); myMap = myMapFragment.getMap(); myMap.setInfoWindowAdapter(new PopupAdapter(getLayoutInflater())); myMap.setOnMapClickListener(new OnMapClickListener() { @Override public void onMapClick(LatLng point) { // Drawing marker on the map drawMarker(point); } }); // Enabling MyLocation in Google Map myMap.setMyLocationEnabled(true); myMap.getUiSettings().setZoomControlsEnabled(true); myMap.getUiSettings().setCompassEnabled(true); myMap.getUiSettings().setMyLocationButtonEnabled(true); myMap.getUiSettings().setAllGesturesEnabled(true); myMap.setTrafficEnabled(true); myMap.animateCamera(CameraUpdateFactory.newLatLngZoom(destLatLng, 6)); markerOptions = new MarkerOptions(); drawMarker(srcLatLng); drawMarker(destLatLng); connectAsyncTask _connectAsyncTask = new connectAsyncTask(); _connectAsyncTask.execute(); }