안드로이드 개발 질문/답변
(글 수 45,052)
SD card Mount /Unmount Intent 관련 문제입니다.
현재 unlock된 G1을 가지고 개발을 하고 있습니다.
Broadcast Receiver와 관련하여 Phone을 USB에 연결/해제 와 관련하여
어플레벨에서 Noti를 받아 Toast를 띄우는데는 성공했습니다.
하지만 SD Card와 관련된 부분은 현재 Toast를 띄우지 않고 있습니다.
아래에 관련 코드 첨부합니다.
능력자 분들의 답변 부탁드려요.
XML Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0" package="com.review">
<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
<activity android:name=".review"
android:label="@string/app_name"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="com.review.IntentReceiver">
<intent-filter>
<action android:name="android.intent.action.UMS_CONNECTED" />
<action android:name="android.intent.action.UMS_DISCONNECTED" />
<action android:name="android.intent.action.MEDIA_MOUNTED" />
<action android:name="android.intent.action.MEDIA_UNMOUNTED" />
<action android:name="android.intent.action.MEDIA_REMOVED" />
<action android:name="android.intent.action_MEDIA_EJECT" />
</intent-filter>
</receiver> -->
</application>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-sdk android:minSdkVersion="4" />
</manifest>
Broadcast Receiver
//com.review.IntentReceiver
package com.review;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;
public class IntentReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals(intent.ACTION_UMS_CONNECTED)) {
Toast.makeText(context, "USB Connected", Toast.LENGTH_LONG).show();
}
if(intent.getAction().equals(intent.ACTION_UMS_DISCONNECTED)) {
Toast.makeText(context, "USB Disconnected", Toast.LENGTH_LONG).show();
}
// BONG_TEST {
if(intent.getAction().equals(intent.ACTION_MEDIA_MOUNTED)) {
Toast.makeText(context, "MOUNTED", Toast.LENGTH_LONG).show();
}
if(intent.getAction().equals(intent.ACTION_MEDIA_UNMOUNTED)) {
Toast.makeText(context, "UNMOUNTED", Toast.LENGTH_LONG).show();
}
if(intent.getAction().equals(intent.ACTION_MEDIA_REMOVED)) {
Toast.makeText(context, "UNMOUNTED", Toast.LENGTH_LONG).show();
}
if(intent.getAction().equals(intent.ACTION_MEDIA_EJECT)) {
Toast.makeText(context, "UNMOUNTED", Toast.LENGTH_LONG).show();
}
// BONG_TEST }
}
}




manifest의 인텐트 필터로 아래와 같이 <data android:scheme="file" />을 넣어주셔야 됩니다.
본 글을 누군가 참고 할지도 모른다는 생각에 리플 달아요~