How to save SMS to inbox in android?

Standard

You can use the SMS content provider to read and write SMS messages:

ContentValues values = new ContentValues();
values.put("address", "123456789");
values.put("body", "This is a test message!");
getContentResolver().insert(Uri.parse("content://sms/inbox"), values);

also add these in manifest:

<uses-permission android:name="android.permission.READ_SMS"/>
<uses-permission android:name="android.permission.WRITE_SMS"/>

How to use Google Analytic for your app

Standard

Introduction

The Google Analytics SDK for Android makes it easy for developers to collect user engagement data from their apps. Developers can then use the Google Analytics app-tracking reports to measure:

  • The number of active users are using their applications.
  • From where in the world the application is being used.
  • Adoption and usage of specific features.
  • In-app purchases and transactions.
  • The number and type of application crashes.
  • And many other useful metrics.

Supporting Multiple Screens Using Drawables Different Density

Standard

Android supports several configuration qualifiers that allow you to control how the system selects your alternative resources based on the characteristics of the current device screen. A configuration qualifier is a string that you can append to a resource directory in your Android project and specifies the configuration for which the resources inside are designed.

How to make an advanced Splash Screen for your Android App

Standard

Create your splash.xml file some thing like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content" 
 android:id="@+id/TheSplashLayout"
 android:layout_gravity="center"
 >
 <ImageView 
 android:layout_width="wrap_content" 
 android:layout_height="wrap_content" 
 android:id="@+id/SplashImageView"
 android:layout_gravity="center" 
 android:src="@drawable/lnxins" 
 >
 </ImageView>
</LinearLayout>

Write your Splash screen java file:

public class SplashScreen extends Activity {
 
 /**
 * The thread to process splash screen events
 */
 private Thread mSplashThread; 

 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);

 // Splash screen view
 setContentView(R.layout.splash);
 
 final SplashScreen sPlashScreen = this; 
 
 // The thread to wait for splash screen events
 mSplashThread = new Thread(){
 @Override
 public void run(){
 try {
 synchronized(this){
 // Wait given period of time or exit on touch
 wait(5000);
 }
 }
 catch(InterruptedException ex){ 
 }

 finish();
 
 // Run next activity
 Intent intent = new Intent();
 intent.setClass(sPlashScreen, MainActivity.class);
 startActivity(intent);
 stop(); 
 }
 };
 
 mSplashThread.start(); 
 }
 
 /**
 * Processes splash screen touch events
 */
 @Override
 public boolean onTouchEvent(MotionEvent evt)
 {
 if(evt.getAction() == MotionEvent.ACTION_DOWN)
 {
 synchronized(mSplashThread){
 mSplashThread.notifyAll();
 }
 }
 return true;
 } 
}

Create apear and disapear animation xml files:

<set xmlns:android="http://schemas.android.com/apk/res/android">
 <alpha
 android:interpolator="@android:anim/accelerate_interpolator"
 android:fromAlpha="0.0" android:toAlpha="1.0"
 android:duration="800"
 />
</set>
<set xmlns:android="http://schemas.android.com/apk/res/android">
 <alpha
 android:interpolator="@android:anim/decelerate_interpolator"
 android:fromAlpha="1.0" android:toAlpha="0.0"
 android:duration="800"
 />
</set>

Add your animation as a style to your style resource file:

<style name="Animations" parent="@android:Animation" />
 <style name="Animations.SplashScreen">
 <item name="android:windowEnterAnimation">@anim/appear</item>
 <item name="android:windowExitAnimation">@anim/disappear</item> 
 </style>
</style>

Add this style to your style resource file for a transparent splash activity:

 <style name="Theme.Transparent" parent="android:Theme">
 <item name="android:windowIsTranslucent">true</item>
 <item name="android:windowBackground">@android:color/transparent</item>
 <item name="android:windowContentOverlay">@null</item>
 <item name="android:windowNoTitle">true</item>
 <item name="android:windowIsFloating">true</item>
 <item name="android:backgroundDimEnabled">false</item>
 <item name="android:windowAnimationStyle">@style/Animations.SplashScreen</item>
 </style>

Add your splash activity to manifest file like this:

<activity 
 android:name="SplashScreen"
 android:theme="@style/Theme.Transparent">
 <intent-filter>
 <action android:name="android.intent.action.MAIN"></action>
 <category android:name="android.intent.category.LAUNCHER"></category>
 </intent-filter>
</activity>

 

Splash Sample

Splash Sample

That’s it…

How to Disable or Manage Android Clear Data

Standard

You have to add this part to your manifest file:

android:manageSpaceActivity=".ActivityOfYourChoice"

and then instead of "Clear Data", there is a button for "Manage Space" which launches ActivityOfYourChoice.

Also you can make a fake activity that do nothing:

public class ActivityOfYourChoice extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);

 finish();
 }
}

Options menu not showing in Android ICS

Standard

Simply change the “android:targetSdkVersion” from “14” to “10” (less then 11), and this problem will be solved.
This is because a theme of “@android:style/Theme.Black.NoTitleBar” specified in manifest – with the “android:targetSdkVersion” of “14“, the options menu is being inserted in to the action bar menu, as opposed to the options menu button in the button bar at the bottom of the screen and the theme is removing the activity title, and the action bar.

How to Hide Android Soft Keyboard

Standard

An open keyboard under your gourdes form is too annoying and takes lots of screen while you design a data entry form in an Android application. To hide soft-keyboard at your form statrup add this tag to your project manifest under activity:

android:windowSoftInputMode="stateHidden"

and it’s gone! (Don’t worry, it will come back when you click on an EditText control)