Wednesday 22 July 2015

Notification Example in Android


How Notification Works in Android?




A notification is a message you can display to the user outside of your application's normal UI. When you tell the system to issue a notification, it first appears as an icon in the notification area. To see the details of the notification, the user opens the notification drawer. Both the notification area and the notification drawer are system-controlled areas that the user can view at any time.


Notification.Builder creates an Notification object.By Using PendingIntent You can Perform an action which will help you to show notification details.

I am Creating an Example, Which will help you to show notifications. After clicking on Button, Notification will appear,After clicking onNotification-it will show you notifications details.


MainActivity.java

public class MainActivity extends Activity {

private static final int NOTIFY_ME_ID = 1337;

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

// OnButton Click Notification Will Appear
public void createNotification(View view) {

final NotificationManager mgr = (NotificationManager) this
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification note = new Notification(R.drawable.ic_launcher,
"Your Status Message!!", System.currentTimeMillis());
// This pending intent will open after notification click
PendingIntent i = PendingIntent.getActivity(this, 0, new Intent(this,
NotificationReceiverActivity.class), 0);

note.setLatestEventInfo(this, "Your Notification Title.",
"Your Notification Message.", i);

// After uncomment this line you will see number of notification arrived
// note.number=2;
mgr.notify(NOTIFY_ME_ID, note);
}

}


activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:onClick="createNotification"
        android:text="Create Notification" />

</LinearLayout>


NotificationReceiverActivity.java

public class NotificationReceiverActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.result);
}

}


result.xml

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

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="This is the result activity opened from the notification" >
    </TextView>

</LinearLayout>


AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.notifi.tst"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="21" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="NotificationReceiverActivity" />
    </application>

</manifest>

Result:





Wednesday 8 July 2015

Android Studio Set-Up and Start Working with Android Studio on Ubuntu


Android Studio Set-Up on Ubuntu.


What is gradle in android?

Ans: Gradle is another build system that takes the best features from other build systems and combines them into one. It also learned from their shortcomings. It is JVM based build system, what that means is that you can write your own script in java, which Android Studio makes use of. One cool thing about gradle is that it is plugin based system. This means if you have your own programming language and you want to automate the task of building some package from sources then you can write a complete plugin in java and distribute it to rest of world.

Similar to Eclipse with the ADT Plugin, Android Studio provides integrated Android developer tools for development and debugging.

On top of the capabilities you expect from IntelliJ, Android Studio offers:

=>Gradle-based build support.
=>Android-specific refactoring and quick fixes.
=>Lint tools to catch performance, usability, version compatibility and other problems.
=>ProGuard and app-signing capabilities.
=>Template-based wizards to create common Android designs and components.
=>A rich layout editor that allows you to drag-and-drop UI components, preview layouts on multiple screen configurations, and much more.
=>Built-in support for Google Cloud Platform, making it easy to integrate Google Cloud Messaging and App Engine as server-side components.


Install Android Studio via PPA in Ubuntu:

Installing Android Studio in Ubuntu becomes easy. A Ubuntu PPA contains simple script that automatically downloads and installs the latest release from Google download server.
Android Studio depends on Java, and Oracle Java 7 or 8 is recommended.

Now Open Your Terminal on Ubuntu and execute following command:
1. sudo add-apt-repository -y ppa:webupd8team/java
2. sudo apt-get update
3. sudo apt-get install oracle-java7-installer oracle-java7-set-default

Here I am Setting Java7 as default.
To add the Android Studio PPA, run the command:
sudo add-apt-repository ppa:paolorotolo/android-studio

Then update package lists and install the script:
sudo apt-get update
sudo apt-get install android-studio

Depends on your internet connection, it takes a few minutes downloading the source package.

Once installed, start the setup wizard from the Unity Dash (may need restart), or just run command /opt/android-studio/bin/studio.sh.

Thursday 18 June 2015

How to install Java on Ubuntu and Updates Java on Ubuntu


How to install Java on Ubuntu and Update it.


Add the webupd8team Java PPA repository in your system and install Oracle Java 8 using following set of commands.

$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
$ sudo apt-get install oracle-java8-installer

After successfully installing oracle Java using above step verify installed version using following command.

$ java -version

java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)

Configuring Java Environment:

In Webupd8 ppa repository also providing a package to set environment variables, Install this package using following command.
$ sudo apt-get install oracle-java8-set-default

If you need the latest Oracle Java 6, you install it too:
sudo apt-get install oracle-java6-installer

If you need the latest Oracle Java 6, you install it too:
sudo update-java-alternatives -s java-7-oracle

If you want test Oracle Java 9 early access builds, you can install it too:
sudo apt-get install oracle-java9-installer

Wednesday 13 May 2015

Rate This App-Link Inside Your Apps on Mobile


How to Rate Your App on Your Mobile.



You can always call getInstalledPackages() from the PackageManager class and check to make sure the market class is installed. You could also use queryIntentActivities() to make sure that the Intent you construct will be able to be handled by something, even if it's not the market application. This is probably the best thing to do actually because its the most flexible and robust.

You can check if the market app is there by:

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://search?q=foo"));
PackageManager pm = getPackageManager();
List<ResolveInfo> list = pm.queryIntentActivities(intent, 0);

You Can also Do in another way!!
You can use the following to launch Android Market on your application's page, it's a bit more automated:

Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("market://details?id=" + getPackageName()));
startActivity(i);

Note: Don't test this in your emulator. If You want to do so, Install google-play on your emulator, then test it.