2013-06-14 3 views
0

이것은 sd 카드의 파일을 보여줄 때 아래의 파일 브라우저 코드입니다. sd 카드에 여러 apk 파일을 넣었지만이 코드는 sd 카드의 apk 파일을 보여 주며 ido를 클릭하면 설치되지 않습니다. 도와주세요. 내가 listview에 표시하지만 어떻게 실행되지 않습니다 apk 파일을 실행하려면 선택한 파일을 실행하려면이 코드를 수정합니까 ??android 어떻게 클릭하면 SD 카드에서 파일을 실행하려면?

  public class MainActivity extends ListActivity { 

private List<String> item = null; 
private List<String> path = null; 
private String root; 
private TextView myPath; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    myPath = (TextView)findViewById(R.id.path); 

    root = Environment.getExternalStorageDirectory().getPath(); 

    getDir(root); 
} 

private void getDir(String dirPath) 
{ 
myPath.setText("Location: " + dirPath); 
item = new ArrayList<String>(); 
path = new ArrayList<String>(); 
File f = new File(dirPath); 
File[] files = f.listFiles(); 

if(!dirPath.equals(root)) 
{ 
    item.add(root); 
    path.add(root); 
    item.add("../"); 
    path.add(f.getParent()); 
} 

for(int i=0; i < files.length; i++) 
{ 
    File file = files[i]; 

    if(!file.isHidden() && file.canRead()){ 
    path.add(file.getPath()); 
     if(file.isDirectory()){ 
     item.add(file.getName() + "/"); 
     }else{ 
     item.add(file.getName()); 
     } 
    } 
} 

    ArrayAdapter<String> fileList = 
    new ArrayAdapter<String>(this, R.layout.row, item); 
    setListAdapter(fileList); 
    } 

@Override 
protected void onListItemClick(ListView l, View v, int position, long id) { 
// TODO Auto-generated method stub 
File file = new File(path.get(position)); 

if (file.isDirectory()) 
{ 
if(file.canRead()){ 
    getDir(path.get(position)); 
}else{ 
    new AlertDialog.Builder(this) 
.setIcon(R.drawable.ic_launcher) 
.setTitle("[" + file.getName() + "] folder can't be read!") 
.setPositiveButton("OK", null).show(); 
} 
}else { 
new AlertDialog.Builder(this) 
.setIcon(R.drawable.ic_launcher) 
.setTitle("[" + file.getName() + "]") 
.setPositiveButton("OK", null).show(); 

} 
} 

} 

답변

0

ListView를 구현하십시오 (다음은 TUTORIAL을 따르십시오).

Intent promptInstall = new Intent(Intent.ACTION_VIEW) 
.setData(Uri.parse("file:///path/to/your.apk")) 
.setType("application/vnd.android.package-archive"); 
startActivity(promptInstall); 

심판 : https://stackoverflow.com/a/4604922/847818

를 한 후 설치를 위해 아래의 snipper를 사용 (listView.onItemClickListener())

그런 다음 항목에 클릭을 처리 할 리스너를 구현

단계별로 이동해야합니다.

+0

어떻게? 어디에 내 코드 에이 코드를 배치 ??? – smartguy1200

+0

이 코드는 도움이되지 않습니다 – smartguy1200

+0

이 코드는 사용법을 알고 있다면 도움이됩니다. 숙제와 구글을해라. – Enrichman

관련 문제