Programming‎ > ‎

AndroidStudio

Started Android Studio Programming in order to create my own music player to my liking (I have 20 Gbyte of music stored in SD card) and was able to create one. I have been using it while walking. Not made public yet.

Updated: 5/31/2021

Index


How to support Android Auto with my app?

I created my music player application but Android auto does not show it as a choice. In order to support Android Auto, you have to do three things as follows:https://developer.android.com/training/cars/media/auto


   1. Set minSdkVersion to Android 5 or higher in Android Manifest.xml
        <uses-sdk android:minSdkVersion="4" android:targetSdkVersion="21 />
   2. Declear media support for Android Auto
        <application>
		...
	       <meta-data android:name="com.google.android.gms.car.application"
               android:resource="@xml/automotive_app_desc"/>
  	    ...
        </application>
   3. Add a resource xml file to res/xml/ directory
        <automotiveApp>
	      <uses name="media" />
    	<automoticApp>
   

Top


Icon size?

Notification icon sizes in pixels are as follows:http://petrnohejl.github.io/Android-Cheatsheet-For-Graphic-Designers/

QualifierDPIScaling factorLauncher iconAction bar, tab iconNotification icon (API 11)Notification icon (API 9)Notification icon (older)
ldpi1200.7536 x 36
32 x 32
24 x 24
18 x 18
18 x 18
16 x 16
12 x 19
12 x 12
19 x 19
16 x 16
mdpi1601.048 x 48
42 x 42
32 x 32
24 x 24
24 x 24
22 x 22
16 x 25
16 x 16
25 x 25
21 x 21
hdpi2401.572 x 72
64 x 64
48 x 48
36 x 36
36 x 36
33 x 33
24 x 38
24 x 24
38 x 38
32 x 32
xhdpi3202.096 x 96
84 x 84
64 x 64
48 x 48
48 x 48
44 x 44
32 x 50
32 x 32
50 x 50
42 x 42
xxhdpi4803.0144 x 144
126 x 126
96 x 96
72 x 72
72 x 72
66 x 66
48 x 75
48 x 48
75 x 75
63 x 63

Notice: the first icon dimension in table cell is full asset size, the second icon dimension is optical square. Dimension values are in pixels.

Top


How can I verify the sign of my apk?

use jarsigner in Program Files\Android\jdk\microsoft_dist_openjdk_1.8.025\bin\jarsigner.

  
  jarsigner -verify -verbose -certs (your).apk
  

Top


Understand the Activity Lifecycle

Somehow many books on Android programming don't mention the activity lifecycle. It is very important to knowhow to create a robust app. Read here https://developer.android.com/guide/components/activities/activity-lifecycle or here https://www.linuxtopia.org/online_books/android/devguide/guide/topics/fundamentals.html.

Top


How to set selected row in RecyclerView?

I created a RecyclerView with TextView ViewHolder. Somehow nobody talks about showing the selected row using a background color.


  @Override    
  public void onBindViewHolder(ViewHolder holder, int position) 
  {        
    String value = mData.get(position);
	holder.myTextView.setText(value);
	if (position == selectedItem)        
	{            
	  holder.itemView.setBackgroundColor(Color.parseColor("#99E4EBEF"));        
	}        
	else        
	{            
	  holder.itemView.setBackgroundColor(Color.parseColor("#99FFFFFF"));        }    
	}    
	...    
	public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener    
	{        
	  TextView myTextView;        
	  ViewHolder(View itemView) 
	  {            
	    super(itemView);            
		myTextView = itemView.findViewById(R.id.rowValue);            
		itemView.setOnClickListener(this);        
	  }        
	  
	  @Override        
	  public void onClick(View view) 
	  {            
	    if (mClickListener != null) 
		{                
		  lastSelected = selectedItem;                
		  selectedItem = getAdapterPosition();                
		  mClickListener.onItemClick(view, selectedItem);                
		  notifyItemChanged(lastSelected);                
		  notifyItemChanged(selectedItem);            
		}        
	  }
	  ...
	}
	

Top


Got ERROR: Failed to resolve: com.android.support:appcompat-v7:28.+

The message was : Add Google Maven repository and sync project
Show in Project Structure dialog
Affected Modules: app

Edit Gradle Scripts -> build.gradle and modify allprojects to have maven:

  allprojects {    
    repositories {        
	    jcenter()        
        maven {            
		    url 'https://maven.google.com/'
		}
		google()
	}
  }
  

Top