Current Android Release version:
Version Code: Pie
Version: 9
API level: 28

Showing posts with label Android Framework. Show all posts
Showing posts with label Android Framework. Show all posts

Multi Window Support in Android N

Android N adds support for displaying more than one app at the same time. On handheld devices, two apps can run side-by-side or one-above-the-other in split-screen mode. On TV devices, apps can use picture-in-picture mode to continue video playback while users are interacting with another app.
In below picture, you can see two apps running side by side.


How to retrieve Telephony information

Phone Type:

switch (mTelephonyManager.getPhoneType()) 
{
      case TelephonyManager.PHONE_TYPE_CDMA:
              mType.setText("CDMA");
              break;
      case TelephonyManager.PHONE_TYPE_GSM:
              mType.setText("GSM");
              break;
      case TelephonyManager.PHONE_TYPE_SIP:
              mType.setText("SIP");
              break;
      default:
              mType.setText("NONE");
              break;
}

Network Type:

switch (mTelephonyManager.getNetworkType()) 
{
       case TelephonyManager.NETWORK_TYPE_1xRTT:
              mNetwork.setText("1xRTT");
              break;
       case TelephonyManager.NETWORK_TYPE_CDMA:
              mNetwork.setText("CDMA");
              break;
       case TelephonyManager.NETWORK_TYPE_EDGE:
              mNetwork.setText("EDGE");
              break;
       case TelephonyManager.NETWORK_TYPE_EHRPD:
              mNetwork.setText("eHRPD");
              break;
       case TelephonyManager.NETWORK_TYPE_EVDO_0:
              mNetwork.setText("EVDO rev. 0");
              break;
       case TelephonyManager.NETWORK_TYPE_EVDO_A:
              mNetwork.setText("EVDO rev. A");
              break;
       case TelephonyManager.NETWORK_TYPE_EVDO_B:
              mNetwork.setText("EVDO rev. B");
              break;
       case TelephonyManager.NETWORK_TYPE_GPRS:
              mNetwork.setText("GPRS");
              break;
       case TelephonyManager.NETWORK_TYPE_HSDPA:
              mNetwork.setText("HSDPA");
              break;
       case TelephonyManager.NETWORK_TYPE_HSPA:
              mNetwork.setText("HSPA");
              break;
      case TelephonyManager.NETWORK_TYPE_HSPAP:
              mNetwork.setText("HSPA+");
              break;
      case TelephonyManager.NETWORK_TYPE_HSUPA:
             mNetwork.setText("HSUPA");
             break;
      case TelephonyManager.NETWORK_TYPE_IDEN:
             mNetwork.setText("iDen");
             break;
      case TelephonyManager.NETWORK_TYPE_LTE:
             mNetwork.setText("LTE");
             break;
      case TelephonyManager.NETWORK_TYPE_UMTS:
             mNetwork.setText("UMTS");
             break;
      case TelephonyManager.NETWORK_TYPE_UNKNOWN:
             mNetwork.setText("Unknown");
             break;
}


SIM State:

switch (mTelephonyManager.getSimState()) 
{
      case TelephonyManager.SIM_STATE_ABSENT:
             mState.setText("Absent");
             break;
      case TelephonyManager.SIM_STATE_NETWORK_LOCKED:
             mState.setText("Network Locked");
             break;
      case TelephonyManager.SIM_STATE_PIN_REQUIRED:
             mState.setText("PIN Required");
             break;
      case TelephonyManager.SIM_STATE_PUK_REQUIRED:
             mState.setText("PUK Required");
             break;
      case TelephonyManager.SIM_STATE_READY:
             mState.setText("Ready");
             break;
      case TelephonyManager.SIM_STATE_UNKNOWN:
             mState.setText("Unknown");
             break;
}

How to get List of Accounts configured in device

private ArrayList<AccountInfo> mAccountList = null;

Account[] mAccount = AccountManager.get(this).getAccounts();
for (Account account : mAccount) {
    AccountInfo list = new AccountInfo(account.name, account.type);
    mAccountList.add(list);
}

How to get Detailed info activity of Application

startActivity(new Intent(
android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
Uri.parse("package:" + mPkg)));

UnInstall Application

Below code will uninstall the application:


Intent intent = new Intent(Intent.ACTION_DELETE);
intent.setData(Uri.parse("package:" + mPkg));
startActivity(intent);

Package Manager in Android

Class for retrieving various kinds of information related to the application packages that are currently installed on the device.

Package: android.content.pm.PackageManager

Android Page:
http://developer.android.com/reference/android/content/pm/PackageManager.html

Source Code:
https://github.com/android/platform_frameworks_base/blob/master/core/java/android/content/pm/PackageManager.java
Use Android package manager pm
usage: pm [list|path|install|uninstall]
       pm list packages [-f]
       pm list permission-groups
       pm list permissions [-g] [-f] [-d] [-u] [GROUP]
       pm list instrumentation [-f] [TARGET-PACKAGE]
       pm list features
       pm path PACKAGE
       pm install [-l] [-r] [-t] [-i INSTALLER_PACKAGE_NAME] [-s] [-f] PATH
       pm uninstall [-k] PACKAGE
       pm enable PACKAGE_OR_COMPONENT
       pm disable PACKAGE_OR_COMPONENT
       pm setInstallLocation [0/auto] [1/internal] [2/external]
Package Manager command line:

Install the package com.twitter.android-1.apk from the SD card
adb shell pm install /sdcard/com.twitter.android-1.apk
List installed packages that contain the term twitter
adb shell pm list packages | grep twitter

Show the install directory of the twitter package
adb shell pm path com.twitter.android


Package Manager stores application information in three files located in /data/system/

1. packages.xml
   This file contains the list of permissions and applications.

2. packages.list
    It is simple text file contain package name, user id ,flag
3. packages-stoped.xml
    This file contain package list which has stopped state.

Activity Manager in Android

Activity Manager will interact with overall activities running in the system.Using the Activity Manager, the Android System manages a stack of activities which are in different states (starting, running, paused, stopped, destroyed).

Package: android.app.ActivityManager


Source Code:

Android Source:
http://developer.android.com/reference/android/app/ActivityManager.html

Activity manager commands:

$ adb shell am
usage: am [start|instrument]
       am start [-a <ACTION>] [-d <DATA_URI>] [-t <MIME_TYPE>]
                [-c <CATEGORY> [-c <CATEGORY>] ...]
                [-e <EXTRA_KEY> <EXTRA_VALUE> [-e <EXTRA_KEY> <EXTRA_VALUE> ...]
                [-n <COMPONENT>] [-D] [<URI>]

1. Launch activity from command prompt
    adb shell am start -n <package>/.<Activity Name>

2. To terminate Application
    adb shell am kill <package name>
    adb shell am force-stop <package name>

3. To start service
    adb shell am startservice <package name>/.<service class>

How to get/set system volume settings?

Audio Manager will help to get/set the volume settings.

public void onCreate(Bundle savedInstanceState) 
{
     super.onCreate(savedInstanceState);
     setContentView(R.layout.volume);

     AudioManager mAudio =                                                                                   (AudioManager)getSystemService(Context.AUDIO_SERVICE);

    SeekBar alarm = (SeekBar)findViewById(R.id.alarm);
    SeekBar music = (SeekBar)findViewById(R.id.music);
    SeekBar ring = (SeekBar)findViewById(R.id.ring);
    SeekBar system = (SeekBar)findViewById(R.id.system);
    SeekBar voice = (SeekBar)findViewById(R.id.voice);

    initControls(alarm, AudioManager.STREAM_ALARM);
    initControls(music, AudioManager.STREAM_MUSIC);
    initControls(ring, AudioManager.STREAM_RING);
    initControls(system, AudioManager.STREAM_SYSTEM);
    initControls(voice, AudioManager.STREAM_VOICE_CALL);

}

private void initControls (SeekBar seek, final int stream) 

{

   seek.setMax(mAudio.getStreamMaxVolume(stream));
   seek.setProgress(mAudio.getStreamVolume(stream));

   seek.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener()    {
       public void onProgressChanged(SeekBar bar, int progress, boolean                                                      fromUser) 
       {
              mAudio.setStreamVolume(stream, progress,                                                                                          AudioManager.FLAG_PLAY_SOUND);
       }
       public void onStartTrackingTouch(SeekBar bar) {
       }
       public void onStopTrackingTouch(SeekBar bar) {
       }
  });
}

How to get List of Installed applications

This code will display the list of applications installed on device.


public class AppsList extends ListActivity 
{
      class AppsAdapter extends ArrayAdapter 
      {
              public AppsAdapter(Context context, int resource,                                                                 List appsList) 
              {
                     super(context, resource, appsList);
                     mContext = context;
                     appList = appsList;
                     mPkm = context.getPackageManager();
              }

      @Override
       public View getView(int position, View convertView, ViewGroup parent) 
       {
               View view = convertView;
               if (null == view) 
               {
                   LayoutInflater inflatter = (LayoutInflater) mContext
                   .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                   view = inflatter.inflate(R.layout.apps_list_items, null);
               }
              mAppInfo = appList.get(position);
              if (null != mAppInfo) 
              {
                   ImageView icon = (ImageView) view.findViewById(R.id.icon);
                   icon.setImageDrawable(mAppInfo.loadIcon(mPkm));
                   ((TextView)                                                                                                                  view.findViewById(R.id.appname)).setText(mAppInfo.loadLabel(mPkm));
      }
      return view;
  }
}
private PackageManager mPkm;
private ApplicationInfo mAppInfo;
private Context mContext;
private List appList = null;

@Override
protected void onCreate(Bundle savedInstanceState) 
{
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          mContext = this;
          mPkm = getPackageManager();
          List appsList = mPkm
          .getInstalledApplications(PackageManager.GET_META_DATA);
          setListAdapter(new AppsAdapter(mContext, R.layout.apps_list_items, appsList));
}
}