2017-07-07 96 views
0

专家您好我想在我的相机应用其中,为用户打开一个应用程序,弹出将与一个选项,在那里保存拍摄的图像,并弹出出现增加一个选项需要包括相机默认的存储文件夹,并用一个选项的子文件夹中创建新的文件夹,重命名选项,然后当按下回车键,无论他捕捉将被保存在同一文件夹中,并有一次,他想将图像保存到一个文件夹,用户应该可以从应用程序栏中的设置中进行选择,按下的设置将显示相同的弹出选项,以及使用相同子文件夹保存拍摄图像的位置。如何捕捉到的图像保存到内部存储

我的主要活动包括

<?xml version="1.0" encoding="utf-8"?> 
 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
 
    package="com.example.sairamkrishna.myapplication" > 
 
    <uses-permission android:name="android.permission.CAMERA" /> 
 
    <application 
 
     android:allowBackup="true" 
 
     android:icon="@drawable/ic_launcher" 
 
     android:label="@string/app_name" 
 
     android:theme="@style/AppTheme" > 
 
     
 
     <activity 
 
     android:name="com.example.sairamkrishna.myapplication.MainActivity" 
 
     android:label="@string/app_name" > 
 
      
 
     <intent-filter> 
 
      <action android:name="android.intent.action.MAIN" /> 
 
      <category android:name="android.intent.category.LAUNCHER" /> 
 
     </intent-filter> 
 
      
 
    </activity> 
 
     
 
    </application> 
 
</manifest>
<?xml version="1.0" encoding="utf-8"?> 
 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 
    xmlns:tools="http://schemas.android.com/tools" 
 
     android:layout_width="match_parent" 
 
    android:layout_height="match_parent" 
 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
 
    android:paddingRight="@dimen/activity_horizontal_margin" 
 
    android:paddingTop="@dimen/activity_vertical_margin" 
 
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"> 
 
</RelativeLayout>
package com.example.sairamkrishna.myapplication; 
 

 
import android.Manifest; 
 
import android.app.Activity; 
 
import android.app.AlertDialog; 
 

 
import android.content.Context; 
 
import android.content.DialogInterface; 
 
import android.content.Intent; 
 
import android.content.SharedPreferences; 
 
import android.content.pm.PackageManager; 
 

 
import android.net.Uri; 
 
import android.os.Bundle; 
 
import android.provider.Settings; 
 

 
import android.support.v4.app.ActivityCompat; 
 
import android.support.v4.content.ContextCompat; 
 
import android.support.v7.app.AppCompatActivity; 
 
import android.support.v7.widget.Toolbar; 
 

 
public class MainActivity extends AppCompatActivity { 
 
    public static final int MY_PERMISSIONS_REQUEST_CAMERA = 100; 
 
    public static final String ALLOW_KEY = "ALLOWED"; 
 
    public static final String CAMERA_PREF = "camera_pref"; 
 

 
    @Override 
 
    protected void onCreate(Bundle savedInstanceState) { 
 
     super.onCreate(savedInstanceState); 
 
     setContentView(R.layout.activity_main); 
 

 
     if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { 
 
     if (getFromPref(this, ALLOW_KEY)) { 
 
      showSettingsAlert(); 
 
     } else if (ContextCompat.checkSelfPermission(this, 
 
      Manifest.permission.CAMERA) 
 
      
 
      != PackageManager.PERMISSION_GRANTED) { 
 
       
 
       // Should we show an explanation? 
 
       if (ActivityCompat.shouldShowRequestPermissionRationale(this, 
 
        Manifest.permission.CAMERA)) { 
 
        showAlert(); 
 
       } else { 
 
        // No explanation needed, we can request the permission. 
 
        ActivityCompat.requestPermissions(this, 
 
        new String[]{Manifest.permission.CAMERA}, 
 
        MY_PERMISSIONS_REQUEST_CAMERA); 
 
       } 
 
      } 
 
     } else { 
 
     openCamera(); 
 
     } 
 
     
 
    } 
 
    public static void saveToPreferences(Context context, String key, Boolean allowed) { 
 
     SharedPreferences myPrefs = context.getSharedPreferences(CAMERA_PREF, 
 
     Context.MODE_PRIVATE); 
 
     SharedPreferences.Editor prefsEditor = myPrefs.edit(); 
 
     prefsEditor.putBoolean(key, allowed); 
 
     prefsEditor.commit(); 
 
    } 
 
\t \t 
 
    public static Boolean getFromPref(Context context, String key) { 
 
     SharedPreferences myPrefs = context.getSharedPreferences(CAMERA_PREF, 
 
     Context.MODE_PRIVATE); 
 
     return (myPrefs.getBoolean(key, false)); 
 
    } 
 
\t \t 
 
    private void showAlert() { 
 
     AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create(); 
 
     alertDialog.setTitle("Alert"); 
 
     alertDialog.setMessage("App needs to access the Camera."); 
 
     
 
     alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "DONT ALLOW", 
 
     new DialogInterface.OnClickListener() { 
 
      public void onClick(DialogInterface dialog, int which) { 
 
       dialog.dismiss(); 
 
       finish(); 
 
      } 
 
     }); 
 
\t \t \t 
 
     alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "ALLOW", 
 
     new DialogInterface.OnClickListener() { 
 
      
 
      public void onClick(DialogInterface dialog, int which) { 
 
       dialog.dismiss(); 
 
       ActivityCompat.requestPermissions(MainActivity.this, 
 
       new String[]{Manifest.permission.CAMERA}, 
 
       MY_PERMISSIONS_REQUEST_CAMERA); 
 
      } 
 
     }); 
 
     alertDialog.show(); 
 
    } 
 
\t \t 
 
    private void showSettingsAlert() { 
 
     AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create(); 
 
     alertDialog.setTitle("Alert"); 
 
     alertDialog.setMessage("App needs to access the Camera."); 
 
     
 
     alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "DONT ALLOW", 
 
     new DialogInterface.OnClickListener() { 
 
      
 
      public void onClick(DialogInterface dialog, int which) { 
 
       dialog.dismiss(); 
 
       //finish(); 
 
      } 
 
     }); 
 
\t \t \t 
 
     alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "SETTINGS", 
 
     new DialogInterface.OnClickListener() { 
 
        
 
      public void onClick(DialogInterface dialog, int which) { 
 
       dialog.dismiss(); 
 
       startInstalledAppDetailsActivity(MainActivity.this); 
 
      } 
 
     }); 
 
\t \t \t 
 
     alertDialog.show(); 
 
    } 
 
\t \t 
 
    @Override 
 
    public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { 
 
     switch (requestCode) { 
 
     case MY_PERMISSIONS_REQUEST_CAMERA: { 
 
      for (int i = 0, len = permissions.length; i < len; i++) { 
 
       String permission = permissions[i]; 
 
      
 
       if (grantResults[i] == PackageManager.PERMISSION_DENIED) { 
 
        boolean 
 
        showRationale = 
 
        ActivityCompat.shouldShowRequestPermissionRationale(
 
        this, permission); 
 
        
 
        if (showRationale) { 
 
        showAlert(); 
 
        } else if (!showRationale) { 
 
        // user denied flagging NEVER ASK AGAIN 
 
        // you can either enable some fall back, 
 
        // disable features of your app 
 
        // or open another dialog explaining 
 
        // again the permission and directing to 
 
        // the app setting 
 
        saveToPreferences(MainActivity.this, ALLOW_KEY, true); 
 
        } 
 
       } 
 
      } 
 
     } 
 
      
 
     // other 'case' lines to check for other 
 
     // permissions this app might request 
 
     } 
 
    } 
 
\t \t 
 
    @Override 
 
    protected void onResume() { 
 
     super.onResume(); 
 
    } 
 
\t \t 
 
    public static void startInstalledAppDetailsActivity(final Activity context) { 
 
     if (context == null) { 
 
     return; 
 
     } 
 
\t \t \t 
 
     final Intent i = new Intent(); 
 
     i.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); 
 
     i.addCategory(Intent.CATEGORY_DEFAULT); 
 
     i.setData(Uri.parse("package:" + context.getPackageName())); 
 
     i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
 
     i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); 
 
     i.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); 
 
     context.startActivity(i); 
 
    } 
 
\t \t 
 
    private void openCamera() { 
 
     Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); 
 
     startActivity(intent); 
 
    } 
 
}

任何帮助将大大赞赏。

回答

0

不是一定要了解你的问题...如果你想存起来通过您的应用程序的一些数据,并能在您的手机,即使你不在线,找回它,你可以使用:window.localStorage

window.localStorage.setItem("itemName", item); // to save it in your phone 
window.localStorage.getItem("itemName"); // to retrieve your item 

要更新您的项目,您可以再次使用setItem(“itemName”,item)。

它回答你的问题吗? :)

相关问题