Android Open Source - TATupload Net Caller






From Project

Back to project page TATupload.

License

The source code is released under:

GNU General Public License

If you think the Android project TATupload listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package uk.org.sucu.tatupload;
/* w  w w. jav a 2 s .  c o m*/
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.provider.Browser;
import android.widget.Toast;

public class NetCaller {

  //While it would be nice to handle everything in-app, it seems for the time being I'll need to go via the browser.
  public static void callScript(Uri uri, Context context){
    //Opens the link in either the default browser or the first one in the list of available apps if multiple are installed
    final Intent browserIntent = new Intent(Intent.ACTION_VIEW);
      browserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      browserIntent.setData(uri);
      //open all this apps requests in the same tab, prevents new ones with each call
      browserIntent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
      //get data about the chosen browser
      Settings settings = new Settings(context);
      String packageName = settings.getChosenBrowserPackage();
      String className = settings.getChosenBrowserName();
      //add it to the intent
      browserIntent.setClassName(packageName, className);
      //start the browser
      context.startActivity(browserIntent);
  }

  public static boolean isOnline(Context context){

    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = cm.getActiveNetworkInfo();
    boolean online =  activeNetworkInfo != null && activeNetworkInfo.isConnected();

    return online;
  }
  //TODO prevent wifi sleep?
  public static boolean isOnlineWithToast(Context context){
    boolean online = isOnline(context);
    
    if(!online){
      Toast.makeText(context, "There is no network connection available.", Toast.LENGTH_SHORT).show();
    }

    return online;
  }

}




Java Source Code List

org.apache.pig.impl.util.ObjectSerializer.java
uk.org.sucu.tatupload.BrowserAccessor.java
uk.org.sucu.tatupload.MessageArrayAdapter.java
uk.org.sucu.tatupload.NetCaller.java
uk.org.sucu.tatupload.Notifications.java
uk.org.sucu.tatupload.ParameterArrayAdapter.java
uk.org.sucu.tatupload.ResolveInfoArrayAdapter.java
uk.org.sucu.tatupload.Settings.java
uk.org.sucu.tatupload.TabContent.java
uk.org.sucu.tatupload.TabManager.java
uk.org.sucu.tatupload.TatUploadApplication.java
uk.org.sucu.tatupload.activity.MainActivity.java
uk.org.sucu.tatupload.activity.OptionActivity.java
uk.org.sucu.tatupload.activity.ParameterViewActivity.java
uk.org.sucu.tatupload.activity.SmsReviewActivity.java
uk.org.sucu.tatupload.activity.TutorialActivity.java
uk.org.sucu.tatupload.message.SmsList.java
uk.org.sucu.tatupload.message.SmsReceiver.java
uk.org.sucu.tatupload.message.Text.java
uk.org.sucu.tatupload.parse.Parameters.java
uk.org.sucu.tatupload.parse.Parser.java
uk.org.sucu.tatupload.parse.Property.java