나는 블루투스를 사용하기 위해 FileDialog와 Intent를 표시하는 기능이 있습니다. 하지만 뒤로 버튼을 누르면 이전 활동이 표시되고 표시되지만 표시 할 수는 없으며 (스크린 샷과 같은) 뒤로 버튼을 다시 한 번 눌러야합니다. 나는 함수 onBackPressed() { finish(); }
을 시도했지만 아무 것도 제대로 동작하지 않았다.이전 작업으로 돌아 가기
MainActivity :
...
if(item == shareMenu) {
startActivity(new Intent(getBaseContext(), ShareViaBluetoothActivity.class));
}
...
ShareViaBluetoothActivity :
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.widget.Toast;
import java.io.File;
import java.util.List;
public class ShareViaBluetoothActivity extends Activity {
private static final int DISCOVER_DURATION = 300;
private static final int REQUEST_BLU = 1;
private FileDialog fileDialog;
public File getFile() {
return file;
}
public void setFile(File file) {
this.file = file;
}
private File file;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
File mPath = new File(Environment.getExternalStorageDirectory(), "//DIR//");
fileDialog = new FileDialog(this, mPath);
fileDialog.addFileListener(new FileDialog.FileSelectedListener() {
public void fileSelected(File file) {
Log.d(getClass().getName(), "selected file " + file.toString());
setFile(file);
sendViaBluetooth();
}
});
fileDialog.showDialog();
}
public void sendViaBluetooth() {
BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
if(btAdapter == null) {
Toast.makeText(this, "Bluetooth is not supported on this device!", Toast.LENGTH_LONG).show();
} else {
enableBluetooth();
}
}
public void enableBluetooth() {
Intent discoveryIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoveryIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, DISCOVER_DURATION);
startActivityForResult(discoveryIntent, REQUEST_BLU);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(resultCode == DISCOVER_DURATION && requestCode == REQUEST_BLU) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("*/*");
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(file.toString())));
intent.setPackage("com.android.bluetooth");
PackageManager pm = getPackageManager();
List<ResolveInfo> appsList = pm.queryIntentActivities(intent, 0);
if(appsList.size() > 0) {
String packageName = null;
String className = null;
boolean found = false;
for(ResolveInfo info : appsList) {
packageName = info.activityInfo.packageName;
if(packageName.equals("com.android.bluetooth")) {
className = info.activityInfo.name;
found = true;
break;
}
}
if (!found) {
Toast.makeText(this, "Bluetooth havn't been found",
Toast.LENGTH_LONG).show();
} else {
intent.setClassName(packageName, className);
startActivity(intent);
}
}
} else {
Toast.makeText(this, "Bluetooth is cancelled", Toast.LENGTH_LONG)
.show();
}
}
}
는 정확히 내가 버튼을 다시 누르면, 그것은 이전의 활동에 관해서'무슨 뜻인지 설명 할 수있다, 그것은 볼 수 있지만 클릭 할 수 없습니다 (화면처럼) 다시 버튼을 눌러야 만합니다. ' –
MainActivity에서 활동을 시작하면 fileDialog가 표시됩니다. 그런 다음 취소하고 싶을 때 "뒤로 누름 버튼"을 누릅니다. 그런 다음 대화 상자가 사라지고 MainActivity는 표시되지만 클릭 할 수는 없습니다. 내 말은, 내가 원할 때마다 화면을 탭할 수 있고 아무 일도 일어나지 않는다는 뜻입니다. 사진과 같은 스크린 샷. "back press button"을 다시 누르면 모든 것이 정상입니다. –
예, 해결 방법은 무엇입니까? finish() 메서드를 시도했지만 작동하지 않습니다. –