标签: android-sdcard

我什么时候应该将我的Android应用程序定义为不能移动到SD卡(installLocation = internalOnly)?

在哪些情况下我应该禁止用户将我的应用程序移动到SD卡(通过设置installLocationinternalOnly)?

我要求了解一些应用程序,所以请不要问我的应用程序.我想知道任何应用程序的一般情况.

android sd-card android-sdcard

8
推荐指数
2
解决办法
3856
查看次数

在Android中格式化SD卡

事情应该很简单,但在大多数情况下,在Android中,不是.如果用户在我的应用程序中选择该选项,我需要格式化SD卡.如果它已经在操作系统中,请不要问我为什么需要这样做...不实用但是我需要实现它.您可能知道,Settings\Storage\Erase SD Card中有一个选项.我看了一下froyo源代码,它是这样的:

final IMountService service =
         IMountService.Stub.asInterface(ServiceManager.getService("mount"));
        if (service != null) {
            new Thread() {
                public void run() {
                try {
                        service.formatVolume(Environment.getExternalStorageDirectory().toString());
                    } catch (Exception e) {
                        // Intentionally blank - there's nothing we can do here
                    Log.w("MediaFormat", "Unable to invoke IMountService.formatMedia()");
                    }
                }
            }.start();
        } else {
            Log.w("MediaFormat", "Unable to locate IMountService");
        }
Run Code Online (Sandbox Code Playgroud)

它使用android.os.storage.IMountServiceandroid.os.ServiceManager我似乎无法访问它.所以,正如我所看到的那样,我可以递归搜索每个文件并将其删除,但这将"不符合我的口味"......或者我可以从Erase SD卡启动屏幕到用户.

任何帮助都是受欢迎的,因为我被困住了.

format android erase android-sdcard

8
推荐指数
1
解决办法
8202
查看次数

无法在Android中创建外部文件目录.WRITE_EXTERNAL_STORAGE存在

我试图用我的两个ApplicationContext和我通话ServiceContext访问外部目录.不幸的是,它一直在返回null,LogCat报告它无法创建外部目录.我确信我有WRITE_STORAGE_PERMISSION现在,但它仍然无效.我的设备正在运行API 10(2.3.3)vanilla android.有任何想法吗?

这是我的清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="droid.signboard" android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="10" />


<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />



<application android:icon="@drawable/icon" android:label="@string/app_name"
    android:name="SignboardApp">
    <receiver android:name=".ApplicationStarter">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED"></action>
            <action android:name="droid.signboard.LAUNCHER_START"></action>
        </intent-filter>
    </receiver>
    <activity android:label="@string/app_name"
        android:screenOrientation="landscape" android:launchMode="singleTop"
        android:name=".view.Signboard">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"></action>
            <category android:name="android.intent.category.LAUNCHER"></category>
        </intent-filter>
    </activity>
    <service android:name=".controller.MasterControllerService">
        <intent-filter>
            <action
                android:name="droid.signboard.LAUNCH_SERVICE_FROM_ACTIVITY"></action>
        </intent-filter>
    </service>


</application>
</manifest>
Run Code Online (Sandbox Code Playgroud)

这里是代码搞砸的地方:

private boolean canWriteEx () …
Run Code Online (Sandbox Code Playgroud)

android android-sdcard

8
推荐指数
2
解决办法
1万
查看次数

如何在Android应用程序中显示图像

我想在我的Android应用程序中以特定大小显示Image.我该怎么做?请指导我?还有一件事我想从SD卡那里得到那张照片.所以请帮助我.

提前致谢.

java android image android-sdcard

8
推荐指数
1
解决办法
3万
查看次数

Android - 通过Intent拍摄照片并使用自定义名称将其保存到自定义目的地

我有一个程序通过Intent打开相机拍照.那部分工作已经很好了.但是,我希望它保存到具有特定文件名的某个文件夹(文件名是可选的,但它确实非常有帮助).

所以这就是我到目前为止所拥有的.

这是打开相机的代码行:

//TODO camera stuff.
Intent openCam = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

//The two lines of code below were commented out at first.
//They were eventually added when I tried to save it with a custom name and destination
fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); // create a file to save the image
openCam.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name

startActivityForResult(openCam, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
Run Code Online (Sandbox Code Playgroud)

结果处理程序在这里:

//TODO handle result
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
   if (resultCode == RESULT_OK) {
         // Image captured and saved to fileUri …
Run Code Online (Sandbox Code Playgroud)

camera android android-sdcard android-camera-intent

8
推荐指数
2
解决办法
6万
查看次数

Android:传输错误:只读文件系统

我想将*.mp3文件推送到我的模拟器中,但它给了我这两个错误:

 transfer error: Read-only file system
 Failed to push selection: Read-only file system
Run Code Online (Sandbox Code Playgroud)

要解决这个问题,我已经完成了这些工作,但仍然无法正常工作:

1 - 使用CMD执行此操作: c:\android-sdk\platform-tools\>abd remount

2 - 将这两行添加到AndroidManifest.xml

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
Run Code Online (Sandbox Code Playgroud)

3 - 将仿真器配置中的SD卡设置为1024 Mb 在此输入图像描述

让我精彩的是文件资源管理器中的sdcard文件夹具有所有必要的权限 在此输入图像描述

eclipse mobile android android-sdcard

8
推荐指数
2
解决办法
2万
查看次数

OutputStreamWriter不会追加

原始代码及其工作将数据保存到SD卡

// Writing data to internal storage
btnSaveData.setOnClickListener(new View.OnClickListener() {

 @Override
 public void onClick(View v) {
   if (isSDCardWritable()) {
      String dataToSave = etData.getText().toString();
         try {
         // SD Card Storage
         File sdCard = Environment.getExternalStorageDirectory();
         File directory = new File(sdCard.getAbsolutePath()+"/MyFiles");
         directory.mkdirs();
         File file = new File(directory, "text.txt");
         FileOutputStream fos = new FileOutputStream(file);
         OutputStreamWriter osw = new OutputStreamWriter(fos);

         // write the string to the file
         osw.write(dataToSave);
         osw.flush();
         osw.close();
         . . . 
Run Code Online (Sandbox Code Playgroud)

然后我更改了代码以根据我的需要添加新值:

            osw.append(dataToSave);
            osw.flush();
            osw.close();
Run Code Online (Sandbox Code Playgroud)

问题是:它覆盖文本文件而不是附加.我错过了什么?谢谢你的帮助

android text-files fileoutputstream android-sdcard

8
推荐指数
1
解决办法
6111
查看次数

Android SAF(存储访问框架):从TreeUri获取特定文件Uri

我正在使用外部SD卡的PersistableUriPermission并将其存储以供进一步使用.现在我希望当用户向我提供文件路径时,从我的应用程序中的文件列表中,我想编辑文档并重命名它.

所以我有要编辑的文件的文件路径.

我的问题是如何从我的TreeUri获取该文件的Uri以及编辑文件.

file-io android android-sdcard storage-access-framework

8
推荐指数
1
解决办法
6254
查看次数

Android共享图片不起作用

我正在尝试使用以下代码共享应用程序的屏幕截图:

View content = findViewById(R.id.layoutHome);
content.setDrawingCacheEnabled(true);
Bitmap bitmap = content.getDrawingCache();

File sdCardDirectory = Environment.getExternalStorageDirectory();
File image = new File(sdCardDirectory,"temp.png");

// Encode the file as a PNG image.
FileOutputStream outStream;
try {
  outStream = new FileOutputStream(image);
  bitmap.compress(Bitmap.CompressFormat.PNG, 100, outStream);
  outStream.flush();
  outStream.close();
} catch (FileNotFoundException e) {
  e.printStackTrace();
} catch (IOException e) {
  e.printStackTrace();
}

String url = "file://" + sdCardDirectory.toString() + "Images/temp.png";

Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("image/*");
String shareBody = "Here is the share content body";
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Subject Here");
sharingIntent.putExtra(android.content.Intent.EXTRA_STREAM, url); …
Run Code Online (Sandbox Code Playgroud)

android android-intent android-sdcard android-sharing

7
推荐指数
1
解决办法
9313
查看次数

Android应用程序移动到sdcard选项是禁用

我所做的应用程序没有选择移动到SD卡...

在我的设置页面中,我没有选择将应用程序移动到SD卡,但其他应用程序有它.为什么会那样?我在做什么错了? 在此输入图像描述

我的应用程序看起来像这样

在此输入图像描述

android android-sdcard

7
推荐指数
2
解决办法
5596
查看次数