Thursday, 31 October 2013

Webview Demo in android

0 comments
Today,we look into a web-view to open a simple link without using browser.

1)Add the web-view in your XML with the following.

        <WebView
        android:id="@+id/webView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />

2)Then write the following code in your activity to display the link in your web-view.

        WebView web;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

web = (WebView) findViewById(R.id.webView1);

web.setWebViewClient(new myWebClient());
web.loadUrl("http://uniqueandroidtutorials.blogspot.in");
}

public class myWebClient extends WebViewClient {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// TODO Auto-generated method stub
super.onPageStarted(view, url, favicon);
}

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub

view.loadUrl(url);
return true;

}
}

// To handle "Back" key press event for WebView to go back to previous screen.
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && web.canGoBack()) {
web.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}

Done..Thanks..

To download the demo Click Here..
Read full post »

Tuesday, 29 October 2013

Android-To draw a line and rounded corner view(like rounded-corner Editext and Button).

0 comments
1)First,To Draw a line in XML by using simple View,Just add this following.

        <View
          android:layout_width="match_parent"
          android:layout_height="1dp"
          android:background="@android:color/black" />

2)Next,For rounded corner view just create an XML in /drawable folder and add this following code.

   round_corner.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <corners
        android:bottomLeftRadius="3dp"
        android:bottomRightRadius="3dp"
        android:radius="3dp"
        android:topLeftRadius="3dp"
        android:topRightRadius="3dp" />
   <solid
       android:color="@android:color/white"/>
   </shape>

3)At last you add this xml in a background to your view like following:-

<EditText
          android:id="@+id/ed1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:background="@drawable/round_corner"
        />

Done..Thanks.
Read full post »

Thursday, 24 October 2013

How To Get The Power And Back Key Event In Android.

0 comments
Hello friends,If you want to perform an action with power and back key pressed look into following.

1)Add this following method in your Activity.(For Power Button Pressed)

 public boolean dispatchKeyEvent(KeyEvent event)
 {
 if (event.getKeyCode() == KeyEvent.KEYCODE_POWER) {
  
 Toast.makeText(getApplicationContext(), "Power button clicked",Toast.LENGTH_LONG).show();

       return true;
 }
     return super.dispatchKeyEvent(event);
}



2)Next,Add this following in your Activity.(For Back Key Pressed)

 @Override
 public void onBackPressed() 
{
        finish();
}

Thanks..
Read full post »

Monday, 7 October 2013

Flurry Agent In Your Android App(To Survey your App)

0 comments
Hello Friends..This post is based how to add Flurry Agent in your App ,the concept is based on track your app through out the world..

1)This will track your app,when you publish your app in market this will give you all the details that how many user's with different area around the world are using the app.From this you will survey your app.

To include Flurry in your App you will perform  following steps in your project:-

1 - Go to flurry.com and register for your app, which will generate you a unique tracking code.

2 - Download  FlurryAgent. jar and add it to your project libraries. In Eclipse, right-click your project folder, select properties, select Java Build Path, and choose Add External JARs.and select this .jar file.

3)Next, In your activities(.java code) you need to add this two methods.
public void onStart()
{
   super.onStart();
   FlurryAgent.onStartSession(this, "Your Key");
   
}

public void onStop()
{
   super.onStop();
   FlurryAgent.onEndSession(this);
}
4)Final Steps to Add android.permission.INTERNET to your AndroidManifest.xml.
For the Unique tracking code(API Key) refer the following steps:-
 -From the Flurry dashboard, under Manage Applications click Add a New Application. Next select the application's platform,enter the application name and category, and then Create App. This will showing you the API key. 
            
                 When your app published to the market you will find all your survey details in your Flurry dashboard.

Thanks..


Read full post »

Saturday, 5 October 2013

Performing Operation On GPS (like checking gps connection,turn on gps,turn off gps)

0 comments
Hello Friends

On today's post you will find  all the operations  regarding GPS. In that you handle your GPS connection and perform operation  Pro-grammatically.

A)First, find solution of Checking the GPS Connection Pro-grammatically with the few simple steps:-

  public Boolean checkGPSProvider() {
LocationManager service = (LocationManager) _context
.getSystemService(_context.LOCATION_SERVICE);
boolean enabled = service
.isProviderEnabled(LocationManager.GPS_PROVIDER);

return enabled;
}

B)Next, You find how to Automatically Turn On GPS Connection.:-

  public void turnGPSOn() {
String provider = Settings.Secure.getString(
_context.getContentResolver(),
Settings.Secure.LOCATION_PROVIDERS_ALLOWED);

if (!provider.contains("gps")) { // if gps is disabled
final Intent poke = new Intent();
poke.setClassName("com.android.settings",
"com.android.settings.widget.SettingsAppWidgetProvider");
poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
poke.setData(Uri.parse("3"));
_context.sendBroadcast(poke);
}

}

C)Last, You find  how to Automatically Turn Off GPS Connection.:-

  public void turnGPSOff() {
String provider = Settings.Secure.getString(
_context.getContentResolver(),
Settings.Secure.LOCATION_PROVIDERS_ALLOWED);

if (provider.contains("gps")) { // if gps is enabled
final Intent poke = new Intent();
poke.setClassName("com.android.settings",
"com.android.settings.widget.SettingsAppWidgetProvider");
poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
poke.setData(Uri.parse("3"));
_context.sendBroadcast(poke);
}
}

For download File....Click Here

Download this file,Copy it into your project and just call this above method..it works..

Thanks..

Read full post »
 

Copyright © Unique Android Tutorial.. Design by Free CSS Templates | Blogger Theme by BTDesigner | Powered by Blogger