3

The music app which is <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="23" />, it works on API 16 , but not in API 23.

The listview is not loaded with songs, it shows empty when checked in API23, working fine in API16.

In API22 also working fine

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;

import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Environment;
import android.view.ContextMenu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SearchView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

public class PlayListActivity extends ListActivity {
    // Songs list
    public ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>();

    SearchView sv;
    ListView lv;
    SimpleAdapter adapter;
    ArrayList<HashMap<String, String>> songsListData = new ArrayList<>();
    int songIndex;

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

        sv = (SearchView)findViewById(R.id.searchView);
        int id = sv.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
        TextView textView = (TextView) sv.findViewById(id);
        textView.setTextColor(Color.WHITE);
        textView.setHintTextColor(Color.LTGRAY);

        SongsManager plm = new SongsManager();
        // get all songs from sdcard
        this.songsList = plm.getPlayList(Environment.getExternalStorageDirectory());

        if(songsList!=null && songsList.size()>0) {
            // looping through playlist
            for (int i = 0; i < songsList.size(); i++) {
                // creating new HashMap
                HashMap<String, String> song = songsList.get(i);

                // adding HashList to ArrayList
                songsListData.add(song);
            }

            // Adding menuItems to ListView
             adapter = new SimpleAdapter(this, songsListData,
                    R.layout.playlist_item, new String[]{"songTitle"}, new int[]{
                    R.id.songTitle});


            setListAdapter(adapter);

            sv.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
                @Override
                public boolean onQueryTextSubmit(String query) {
                    return false;
                }

                @Override
                public boolean onQueryTextChange(String newText) {
                    adapter.getFilter().filter(newText);
                    return false;
                }
            });
            // selecting single ListView item
             lv = getListView();

            // register for context menu
            registerForContextMenu(lv);

            // listening to single listitem click
            lv.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> parent, View view,
                                        int position, long id) {
                    // getting listitem index
                    songIndex = position;

                    // Starting new intent
                    Intent in = new Intent(getApplicationContext(),
                            MainActivity.class);
                    // Sending songIndex to PlayerActivity
                    in.putExtra("songIndex", songIndex);
                    setResult(100, in);
                    // Closing PlayListView
                    finish();
                }
            });
        }

        sv.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(final View view, boolean hasFocus) {
                if (hasFocus) {
                    view.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
                            imm.showSoftInput(view.findFocus(), 0);
                        }
                    }, 200);
                }
            }
        });
    }
    //ListView listView = (ListView)findViewById(android.R.id.list);
    @Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
        super.onCreateContextMenu(menu, v, menuInfo);

        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.playlist_contextmenu,menu);
    }

    @Override
    public boolean onContextItemSelected(MenuItem item) {
        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();

        switch (item.getItemId()){

            case R.id.delete_id:
                songsListData.remove(info.position);
                String path =  songsList.get(info.position).get("songPath");
                File filepath = new File(path);
                filepath.delete();
                adapter.notifyDataSetChanged();
                return true;
            default:
                return super.onContextItemSelected(item);
        }

    }
}

Even the Notification icon doesn't show up, it shows empty icon I have used NotificationCompat.Builder

ListView

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">
    <SearchView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/searchView"
        android:background="#242424" //black colour
        android:queryHint="Search...">
    </SearchView>
    <ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:divider="@drawable/gradient_horizontal_line"
        android:dividerHeight="1dp"
        android:listSelector="@drawable/list_selector" // balck colour
        android:background="@drawable/list_selector"/>

</LinearLayout>

List Item

<?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:orientation="vertical"
    android:gravity="center"
    android:background="@drawable/list_selector"
    android:foreground="#EBEBEB"
    android:padding="5dp">
    <!--android:background="@drawable/list_selector"-->
    <TextView 
        android:id="@+id/songTitle"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="16dp"
        android:padding="10dp"
        android:background="@drawable/list_selector"
        android:textColor="#FFFFFF"/>  // white colour
    <!--android:color="#f3f3f3"-->
</LinearLayout>

list_selector

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Selector style for listrow -->

    <item 
     android:state_selected="false"
        android:state_pressed="false" 
        android:drawable="@drawable/gradient_bg" />
    <item android:state_pressed="true" 
        android:drawable="@drawable/gradient_bg_hover" />
    <item android:state_selected="true"
     android:state_pressed="false" 
        android:drawable="@drawable/gradient_bg_hover" />
    </selector>

Styles.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

    <style name="btnStyleBlackpearl" parent="@android:style/Widget.Button">
        <item name="android:textSize">15sp</item>
        <item name="android:textStyle">bold</item>
        <item name="android:textColor">#C4C4C4</item>
        <item name="android:gravity">center</item>
        <item name="android:shadowColor">#000000</item>
        <item name="android:shadowDx">1</item>
        <item name="android:shadowDy">1</item>
        <item name="android:shadowRadius">0.6</item>
        <item name="android:background">@drawable/custom_btn_black_pearl</item>
        <item name="android:padding">10dip</item>
    </style>

</resources>

please guide..

API 16 - working

API 23 - not working - after turned on storage permission in emulator enter image description here

Community
  • 1
  • 1
Selva
  • 1,310
  • 2
  • 14
  • 31
  • If you target API >= 21 your notifications will have just white color. Every opaque pixel will be white. Make an icon which uses alpha channel to work with contrast. – Eugen Pechanec Feb 27 '16 at 07:30
  • @ Eugen Pechanec, Even after using alpha channel, notification icon shows in white colour only.. – Selva Mar 01 '16 at 11:02
  • Which is what I said in the first sentence. This is intended behavior since Lollipop. – Eugen Pechanec Mar 01 '16 at 11:52

5 Answers5

1

For a quick fix: on the device/emulator goto Settings -> Apps -> Your App -> Permissions and make sure Storage is checked on. Long term, you want your app to request permissions at run time using the new APIs added in API 23.

Alex Townsend
  • 1,564
  • 10
  • 13
  • I have turned on the storage permission in emulator, but bit improvement in showing up the listview. Earlier it was complete black screen and after storage permission turned on now list view is showing white screen with horizontal list items, with empty text, but if I click any items songs are playing. and still notification icon doesn't shows up. please see the screen shot above. – Selva Feb 26 '16 at 10:33
  • Check your text colors and styles. If it's the same color between both screenshots you're just using a white text on a white/light background. – Alex Townsend Feb 26 '16 at 14:17
  • Could you post your layout for the list items as well as your `styles.xml` file(s)? – Alex Townsend Feb 26 '16 at 15:39
  • What is your `@drawable/list_selector` code? Are you using `AppCompat`? Please post your `styles.xml` if you can. – Alex Townsend Feb 26 '16 at 18:20
  • Try changing your parent style for your button to `Widget.AppCompat.Button`, also in your list_selector.xml, put this as the last option: `` (assuming this is the default background that you want). – Alex Townsend Feb 27 '16 at 14:42
  • thanks for your time, I found the issue and posted the answer. – Selva Feb 28 '16 at 05:48
0

You Should Handle Storage permissions Programmatically in MarshMallow Devices.

Ramana Reddy
  • 102
  • 10
0
  • Hey check your styles.
  • Your list colour is different in provide api images.
  • I think the list item text colour is WHITE so its not visible in api 23.
  • try to change that colour and I'm sure it'll work.

*Note - Please keep similar theme accross all api.

kevz
  • 2,727
  • 14
  • 39
  • yes text colour is White, but I have set the List item and list view colour as black, why it is not occurring only in API 23? – Selva Feb 26 '16 at 15:04
0

I think the textColor is white. So you are not able to see the row items. You can change the textcolor and everything will work fine

Goodluck!

Avani Nagar
  • 96
  • 1
  • 11
0

I found the problem, it is android:foreground="#EBEBEB" which is white colour in list item linear layout.

Selva
  • 1,310
  • 2
  • 14
  • 31