2016-04-06 21 views
1

Bu kod 4.2 ve altında çalışıyor, ancak 4.4 veya üstü üzerinde çalışıyor.Ne yazık ki uygulama çalışmayı durdurdu hatası nedenini bilmiyorum. android için yeni olduğum gibi. Kullanımdan kaldırılan yöntemler yüzünden değil mi? ya da ne ?müzik listesi görünümü 4.4 veya üstü üzerinde çalışmıyor mu?

This is my Stacktrace

Ve aşağıdaki kodum: Ben senin Logtrace gördüğünüz gibi size gelen medya verileri okumak için bu izni gerektiğinden

package com.example.hamza; 

import android.app.Activity; 
import android.content.ContentResolver; 
import android.content.Context; 
import android.database.Cursor; 
import android.os.Bundle; 
import android.provider.MediaStore; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.BaseAdapter; 
import android.widget.ListView; 
import android.widget.TextView; 

public class MainActivity extends Activity{ 
    ListView lvfs; 
    Cursor cursorfm; 
    int count,middleperson; 
    TextView tv,title; 
    ContentResolver conres; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     initializesomestuff(); 
    } 

    private void initializesomestuff() { 
     // TODO Auto-generated method stub 
     lvfs=(ListView)findViewById(R.id.lview); 
     findViewById(R.id.tv1); 
     String[] projection={MediaStore.Audio.Media._ID,MediaStore.Audio.Media.DISPLAY_NAME,MediaStore.Audio.Media.ARTIST,}; 
     cursorfm=conres.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, projection, null, null,null); 
     count=cursorfm.getCount(); 
     ////get some data 
     lvfs.setAdapter(new musiclistadapter(getApplicationContext())); 

    } 
    /////// cutomiztion walla area///start 
public class musiclistadapter extends BaseAdapter{ 


private Context mcontext; 
String songname,songartist; 
private LayoutInflater mLayoutInflater; 

    public musiclistadapter(Context applicationContext) { 
    // TODO Auto-generated constructor stub 
     mcontext=applicationContext; 
     //get the layout inflater 
     mLayoutInflater = (LayoutInflater) mcontext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
} 

    @Override 
    public int getCount() { 
     // TODO Auto-generated method stub 
     return count; 
    } 

    @Override 
    public Object getItem(int position) { 
     // TODO Auto-generated method stub 
     return position; 
    } 

    @Override 
    public long getItemId(int position) { 
     // TODO Auto-generated method stub 
     return position; 
    } 

    @Override 
    public View getView(int position, View arg1, ViewGroup arg2) { 
     // TODO Auto-generated method stub 
     ViewHolder holder; 
     System.gc(); 
     tv = new TextView(mcontext.getApplicationContext()); 
     String id=null; 
     //if(arg1==null){ 
     holder = new ViewHolder(); 
     arg1 = mLayoutInflater.inflate(R.layout.textviewlayout, arg2, false); 
     // get all views you need to handle from the cell and save them in the view holder 
     holder.itemName = (TextView) arg1.findViewById(R.id.tv1); 
     // save the view holder on the cell view to get it back latter 

      middleperson=cursorfm.getColumnIndexOrThrow(MediaStore.Audio.Media.DISPLAY_NAME); 
      cursorfm.moveToPosition(position); 
      id=cursorfm.getString(middleperson); 
      middleperson=cursorfm.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST); 
      cursorfm.moveToPosition(position); 
      id=id+cursorfm.getString(middleperson); 
      arg1.setTag(holder); 
      holder.itemName.setText(id); 
      //middleperson=cursorfm.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST); 
      //id=cursorfm.getString(middleperson); 
      //id+="whatever it is"+id+cursorfm.getString(middleperson); 
      //LayoutInflater inflater = getLayoutInflater(); 
      //View row; 
      //row = inflater.inflate(R.layout.textviewlayout, arg2, false); 
      // TextView title; 
      // title = (TextView) row.findViewById(R.id.tv1); 
      // title.setText(id); 
      //tv.setText(id); 
      // return (row); 
    // } 
     //else{ 
      //title = (TextView) arg1; 
      // the getTag returns the viewHolder object set as a tag to the view 
      holder = (ViewHolder)arg1.getTag(); 
     //} 

     //if (id != null) { 
       //set the item name on the TextView 
       //holder.itemName.setText(cursorfm.getString(middleperson)); 
      // } else { 
       // make sure that when you have an if statement that alters the UI, you always have an else that sets a default value back, otherwise you will find that the recycled items will have the same UI changes 
      // holder.itemName.setText("Unknown"); 
      // } 

      //this method must return the view corresponding to the data at the specified position. 
      return arg1; 
     //return (title); 

    } 
} 
private class ViewHolder { 

    protected TextView itemName; 

} 
} 
+0

Logcat izniniz nedir? –

+0

izinsiz giriş hatası alıyorsunuz, android 6.0 (Marshmallow) için ve gerçek zamanlı izinlere ihtiyacınız var – 1234567

cevap

0

, sen READ_EXTERNAL_STORAGE iznini vermedi cihaz. Yani, manifest.xml dosyayı açın ve application etiketinden önce aşağıdaki izni eklemek zorunda: Medya depolama konumu farklılık nedeniyle


Ve bazı cihazlarda çalışan ve diğerlerinde çalışmıyor hakkında

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> 
, işte farklı cihazlar ve android sürümleri arasında, müzik medya verileri bazı cihazlarda (ve dolayısıyla izne ihtiyacınız olacak) harici depolamada saklanır, ve diğerleri değil.

İlgili konular