Action send intent will pickup all the installed application and shown in a popup.
if we want customize this popup. we can get the the individual installed app and
we can filter the popup list.
example:
/**
* this method will give all the installed applications
*/
public void getInstalledPackages() {
List<ResolveInfo> activities = context.getPackageManager().queryIntentActivities(
sendIntent, 0);
final Object a[] = activities.toArray();
for (int i = 0; i < activities.size(); i++) {
Drawable appicon;
* this method will give all the installed applications
*/
public void getInstalledPackages() {
List<ResolveInfo> activities = context.getPackageManager().queryIntentActivities(
sendIntent, 0);
final Object a[] = activities.toArray();
for (int i = 0; i < activities.size(); i++) {
Drawable appicon;
//gets the app name
String temp = ((ResolveInfo) a[i]).activityInfo.applicationInfo
.loadLabel(context.getPackageManager()).toString();
String temp = ((ResolveInfo) a[i]).activityInfo.applicationInfo
.loadLabel(context.getPackageManager()).toString();
//gets the app icon
appicon = ((ResolveInfo) a[i]).activityInfo.applicationInfo
.loadIcon(context.getPackageManager());
appicon = ((ResolveInfo) a[i]).activityInfo.applicationInfo
.loadIcon(context.getPackageManager());
//saving in array list.
listmessages.add(temp);
currentDisp.add((ResolveInfo) a[i]);
drawbles.add(appicon);
}
}
listmessages.add(temp);
currentDisp.add((ResolveInfo) a[i]);
drawbles.add(appicon);
}
}
//inflating the custom layou
dialog = new Dialog(context, R.style.Theme_Dialog_Translucent);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.shownetworksdialogue);
listview = (ListView)dialog.findViewById(R.id.networklist);
TextView okbuton = (TextView)dialog.findViewById(R.id.shownetworkok);
TextView dialougeTitle = (TextView)dialog.findViewById(R.id.dialogtitle);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.shownetworksdialogue);
listview = (ListView)dialog.findViewById(R.id.networklist);
TextView okbuton = (TextView)dialog.findViewById(R.id.shownetworkok);
TextView dialougeTitle = (TextView)dialog.findViewById(R.id.dialogtitle);
listview.setAdapter(new CustomAdapter());
CustomAdapter class:
public class CustomAdapter extends BaseAdapter {
public int getCount() {
return listmessages.size();
}
public Object getItem(int arg0) {
return arg0;
}
public long getItemId(int arg0) {
return arg0;
}
public View getView(final int position, View convertView, ViewGroup parent) {
Holder holderView = null;
if (convertView == null) {
holderView = new Holder();
convertView = inflater.inflate(R.layout.networklist, null);
holderView.network = (TextView) convertView
.findViewById(R.id.gmail);
holderView.launcheicon=(ImageView) convertView.findViewById(R.id.launchericon);
convertView.setTag(holderView);
} else {
holderView = (Holder) convertView.getTag();
}
holderView.launcheicon.setImageDrawable(drawbles.get(position));
holderView.network.setText(listmessages.get(position));
return convertView;
}
}
//holder class
private class Holder {
TextView network;
RelativeLayout viewinfolayout,viewinfomainsiblinglayout;
ImageView launcheicon;
}
TextView network;
RelativeLayout viewinfolayout,viewinfomainsiblinglayout;
ImageView launcheicon;
}
networklist xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:facebook="http://schemas.android.com/apk/res-auto"
android:id="@+id/popupbg"
android:layout_width="fill_parent"
android:layout_height="48dip" >
android:orientation="horizontal"
<ImageView
android:id="@+id/launchericon"
android:layout_width="42dp"
android:layout_height="42dp"
/>
<TextView
android:id="@+id/gmail"
style="@style/textviewwrapcontent"
android:text="@string/gmail"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:facebook="http://schemas.android.com/apk/res-auto"
android:id="@+id/popupbg"
android:layout_width="fill_parent"
android:layout_height="48dip" >
android:orientation="horizontal"
<ImageView
android:id="@+id/launchericon"
android:layout_width="42dp"
android:layout_height="42dp"
/>
<TextView
android:id="@+id/gmail"
style="@style/textviewwrapcontent"
android:text="@string/gmail"
android:textStyle="bold" />
</LinearLayout>
shownetworksdialogue xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="48dp"
android:layout_marginBottom="72dp"
android:background="@color/lightblack"
android:orientation="vertical" >
<include android:id="@+id/showpopop" layout="@layout/popupheading"/>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/bellwolay"
android:layout_below="@+id/showpopop"
>
<ListView android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/networklist"></ListView>
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:id="@+id/bellwolay"
android:orientation="vertical">
<View android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="@color/thinkbule"/>
<TextView
style="@style/popupbottom"
android:id="@+id/shownetworkok"
android:text="@string/cancel"
android:gravity="center"/>
</LinearLayout>
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="48dp"
android:layout_marginBottom="72dp"
android:background="@color/lightblack"
android:orientation="vertical" >
<include android:id="@+id/showpopop" layout="@layout/popupheading"/>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/bellwolay"
android:layout_below="@+id/showpopop"
>
<ListView android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/networklist"></ListView>
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:id="@+id/bellwolay"
android:orientation="vertical">
<View android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="@color/thinkbule"/>
<TextView
style="@style/popupbottom"
android:id="@+id/shownetworkok"
android:text="@string/cancel"
android:gravity="center"/>
</LinearLayout>
</RelativeLayout>
No comments:
Post a Comment