File Save code is not saving file in internal storage - Java for Android App Development

i want to save a layout (relative layout), when i run the app everything is working fine, but i am unable to find saved file/s in the internal storage of the phone. Any help would be appreciated as i am new and unable to sort out what is going wrong . here is my code
Code:
public void saveMe(View v) {
// get prompts.xml view
LayoutInflater li = LayoutInflater.from(this);
View promptsView = li.inflate(R.layout.prompt, null);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
context);
// set prompt.xml to alertdialog builder
alertDialogBuilder.setView(promptsView);
final EditText userInput = (EditText) promptsView
.findViewById(R.id.editTextDialog);
// set dialog message
alertDialogBuilder.setCancelable(false);
alertDialogBuilder.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
final String fileName = userInput.getText().toString();
final View view1=findViewById(R.id.relativeLayout); // The view that you want to save as an image
Bitmap bitmap = Bitmap.createBitmap(view1.getWidth(), view1.getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(bitmap);
view1.draw(c);
if(fileName.length() == 0)
Toast.makeText(EidCardFinal.this,"Please Enter File Name",Toast.LENGTH_SHORT).show();
else{
File file = new File(context.getFilesDir(), fileName);
if (file.exists())
Toast.makeText(EidCardFinal.this,"File Already Exists",Toast.LENGTH_SHORT).show();
else{
try{
FileOutputStream out = new FileOutputStream(file);
bitmap.compress(CompressFormat.PNG, 100, out);
Toast.makeText(EidCardFinal.this,"File Saved",Toast.LENGTH_SHORT).show();
out.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
}
});
alertDialogBuilder.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
}

Try adding a line:
out.flush();
just before calling close() on the FileOutputStream. I think this will get the save code to work, and it's worth trying.

ExoComet said:
Try adding a line:
out.flush();
just before calling close() on the FileOutputStream. I think this will get the save code to work, and it's worth trying.
Click to expand...
Click to collapse
thanks for the suggestion, but i have opted for the external storage and its working fine

Related

database connect doesn't work properly

i've need to connect my app to an external database so i put my sqlite database on assets folder and i've follow this tutorial to make DBHelper.
now i want to show some record of database in my app but when i launch it, it give me an error like a table "linee" doesn't exists on my database but it exists!!!! this link cans proof it http://img689.imageshack.us/img689/926/ytvo.png
why???? it's a week that i can to fix this problem but i can't solve it
this is MyOpenHelper
Code:
public class MyOpenHelper extends SQLiteOpenHelper{
//The Android's default system path of your application database.
private static String DB_PATH ;
private SQLiteDatabase db;
private static String DB_NAME = "orari";
private final Context myContext;
public MyOpenHelper(Context context) {
super(context, DB_NAME, null, 1);// 1? its Database Version
if(android.os.Build.VERSION.SDK_INT >= 4.2){
DB_PATH = context.getApplicationInfo().dataDir + "/databases/";
} else {
DB_PATH = "/data/data/" + context.getPackageName() + "/databases/";
}
this.myContext = context;
}
public void createDataBase() throws IOException{
boolean dbExist = checkDataBase();
if(dbExist){
}else{
this.getReadableDatabase();
try{
copyDataBase();
}catch (IOException e){
throw new Error("Errore nel copiare il database");
}
}
}
private boolean checkDataBase(){
File dbFile=new File(DB_PATH+DB_NAME);
return dbFile.exists();
}
private void copyDataBase() throws IOException{
InputStream myInput=myContext.getAssets().open(DB_NAME);
String outFileName = DB_PATH+DB_NAME;
OutputStream myOutput=new FileOutputStream(outFileName);
byte[] buffer = new byte [1024];
int length;
while ((length=myInput.read(buffer))>0){
myOutput.write(buffer, 0, length);
}
myOutput.flush();
myOutput.close();
myInput.close();
}
public void openDataBase() throws SQLException{
String myPath=DB_PATH+DB_NAME;
db=SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);
}
[user=439709]@override[/user]
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
}
[user=439709]@override[/user]
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
}
}

Retrieving cpu frequency

Hi everyone.
I want to retrieve the current cpu frequency in my app but I don't seem to be right.
In my code I want to read the "scaling_cpu_freq" file from internal storage.
This is the code:
Code:
private String ReadCPUMhz() {
String cpuMaxFreq = "";
int cur = 0;
try {
[user=1299008]@supp[/user]ressWarnings("resource")
BufferedReader maxi = new BufferedReader(new FileReader(new File("/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq")));
try{
cpuMaxFreq = maxi.readLine();
cur = Integer.parseInt(cpuMaxFreq);
cur = cur/1000;
} catch (Exception ex){
ex.printStackTrace();
}
} catch (FileNotFoundException f) {
f.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return String.valueOf(cur);
}
The problem is that the method only returns 0, which is the initial value of the int "cur".
Can anybody help me?
Thanks in advance.
Here's the code I use:
Declare this class in your Activity
Code:
// Read current frequency from /sys in a separate thread
// This class assumes your TextView is declared and referenced in the OnCreate of the class this one is declared in
// And its variable name is mCurCpuFreq
protected class CurCPUThread extends Thread {
private static final String CURRENT_CPU = "/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq";
private boolean mInterrupt = false;
public void interrupt() {
mInterrupt = true;
}
[user=439709]@override[/user]
public void run() {
try {
while (!mInterrupt) {
sleep(400);
final String curFreq = readOneLine(CURRENT_CPU);
mCurCPUHandler.sendMessage(mCurCPUHandler.obtainMessage(0,
curFreq));
}
} catch (InterruptedException e) {
return;
}
}
}
// Update real-time current frequency & stats in a separate thread
protected static Handler mCurCPUHandler = new Handler() {
public void handleMessage(Message msg) {
mCurFreq.setText(toMHz((String) msg.obj));
final int p = Integer.parseInt((String) msg.obj);
new Thread(new Runnable() {
public void run() {
// Here I update a real-time graph of the current freq
}
}
}).start();
}
};
Helper methods used :
Code:
// Convert raw collected values to formatted MhZ
private static String toMHz(String mhzString) {
if (Integer.valueOf(mhzString) != null)
return String.valueOf(Integer.valueOf(mhzString) / 1000) + " MHz";
else
return "NaN";
}
// Iterate through the /sys file
public static String readOneLine(String fname) {
BufferedReader br;
String line = null;
try {
br = new BufferedReader(new FileReader(fname), 512);
try {
line = br.readLine();
} finally {
br.close();
}
} catch (Exception e) {
Log.e(TAG, "IO Exception when reading sys file", e);
// attempt to do magic!
return readFileViaShell(fname, true);
}
return line;
}
// Backup method if the above one fails
public static String readFileViaShell(String filePath, boolean useSu) {
CommandResult cr = null;
if (useSu) {
cr = new CMDProcessor().runSuCommand("cat " + filePath);
} else {
cr = new CMDProcessor().runShellCommand("cat " + filePath);
}
if (cr.success())
return cr.getStdout();
return null;
}
CMDProcessor.java and its dependencies attached to this post

Create pref and move it to another location

Sorry for the unclear title. What I'm trying to do is the following:
Code:
Button btncheat = (Button) findViewById(R.id.button1);
final EditText score = (EditText) findViewById(R.id.editText1);
btncheat.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String filename = "FlappyBird.xml";
String string = "<?xml version='1.0' encoding='utf-8' standalone='yes' ?>\n<map>\n<int name=\"score\" value=\"" + score.getText().toString() + "\" />\n</map>";
FileOutputStream outputStream;
try {
outputStream = openFileOutput(filename, Context.MODE_PRIVATE);
outputStream.write(string.getBytes());
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
try {
String[] commands = {"mv /data/data/de.aciid.nullgc/files/FlappyBird.xml /data/data/com.dotgears.flappybird/shared_prefs/"};
RunAsRoot(commands);
} catch (Exception e) {
e.printStackTrace();
}
}
});
So, it creates the XML file from the String "string" (I don't know if I can do it like this, but the XML file looks right in the end) and move it to /data/data/com.dotgears.flappybird/shared_prefs/. The creation and moving of the XML file works flawless, but Flappy Bird does not read the pref properly. When I start the game, it says that my highscore is zero, although the score 999 (for example) is in the XML file. As I stated, the XML file looks right, I pasted an original and my modded XML in an online script and there are no differences whatsoever.
So why doesn't this work?

FileChooser no Jpg

Hi. I´m from Germany. Sorry for my bad English.
On my Work, there is a Server with Wlan. The Page on this Server is like a Forum (Like XDA).
I´m a beginner in Android, but my app is 90% finish.
Now my Problem. In the Forum page there is "like XDA" an upload button. I have make my Filechooser but there is the problem. When i upload test.pdf or test.bmp. Server says ok, name of the file is test.pdf or test.bmp. So i can upload
My problem is only with jpg. When Filechooser open and i choose the jpg (sdcard0 oder extsdcard) the name on the server gives the picture a number. That means test.jpg = 1983 . Can´t upload.
I hope you understand me, and can give me a fix. Thanks for Help!!!
Here my Code
HTML:
webView.setWebChromeClient(new WebChromeClient() {
public void openFileChooser(ValueCallback<Uri> uploadMsg) {
mUploadMessage = uploadMsg;
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("*/*");
startActivityForResult(Intent.createChooser(i, "File Chooser"),
MainActivity.FILECHOOSER_RESULTCODE);
}
// For Android 3.0+
public void openFileChooser(ValueCallback uploadMsg,
String acceptType) {
mUploadMessage = uploadMsg;
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("*/*");
startActivityForResult(Intent.createChooser(i, "File Chooser"),
MainActivity.FILECHOOSER_RESULTCODE);
;
}
// For Android 4.1
public void openFileChooser(ValueCallback<Uri> uploadMsg,
String acceptType, String capture) {
mUploadMessage = uploadMsg;
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("*/*");
startActivityForResult(Intent.createChooser(i, "File Chooser"),
MainActivity.FILECHOOSER_RESULTCODE);
}
});
}
[user=439709]@override[/user]
protected void onActivityResult(int requestCode, int resultCode,
Intent intent) {
if (requestCode == FILECHOOSER_RESULTCODE) {
if (null == mUploadMessage)
return;
Uri result = intent == null || resultCode != RESULT_OK ? null
: intent.getData();
String filePath = result.getPath();
mUploadMessage.onReceiveValue(result);
mUploadMessage = null;
}
}
Hi. Nobody can help me? Plz. I need it.
Plz help. I need it. I spend much time, but i can´t find a fix.

[Q] How do I add an image picker to my app, show it in image view, then save it to pa

This is what I have:
Code:
package JEB.ssf;
import android.app.*;
import android.os.*;
import android.widget.*;
import android.view.*;
import android.view.View.*;
import com.parse.*;
import android.content.*;
import android.support.v4.app.*;
import java.util.*;
import android.widget.AdapterView.*;
import android.util.*;
import com.google.android.gms.ads.*;
import com.google.ads.mediation.*;
import com.google.ads.*;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdListener;
import android.provider.*;
import android.database.*;
import android.graphics.*;
public class ProfilePage extends Activity
{
private static int LOAD_IMAGE_RESULTS = 1;
// GUI components
private Button button; // The button
private ImageView image;// ImageView
Spinner sp1,sp2;
ArrayAdapter<String> adp1,adp2, adp3;
List<String> l1,l2, l3;
int pos;
EditText fname, lname, hf, hi, weight,
waist, wrist, hip, forearm, age, goal;
TextView userName, gender, category, unit;
String hftxt, hitxt, id, firstNameTxt, userNameTxt, posttxt, postnum;
Button share;
float obid;
int in;
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.profile_page);
getActionBar().setDisplayHomeAsUpEnabled(true);
Parse.initialize(this, "abmPl8JnnhyaqjA0Pp8ZWmptKTCeV0p8eoMEHPaL", "icKQxW5AdPXHJtsGEqSX5LwJ2Dd8zt0USKd1PNeP");
fname = (EditText) findViewById(R.id.first_name);
lname = (EditText) findViewById(R.id.last_name);
hf = (EditText) findViewById(R.id.height_feet);
hi = (EditText) findViewById(R.id.height_inch);
weight = (EditText) findViewById(R.id.weight_lbs);
waist = (EditText) findViewById(R.id.waist);
wrist = (EditText) findViewById(R.id.wrist);
hip = (EditText) findViewById(R.id.hip);
forearm = (EditText) findViewById(R.id.forearm);
age = (EditText) findViewById(R.id.age);
userName = (TextView) findViewById(R.id.user_name);
gender = (TextView) findViewById(R.id.gender);
category = (TextView) findViewById(R.id.category);
unit =(TextView) findViewById(R.id.unit);
goal =(EditText) findViewById(R.id.goal);
share = (Button) findViewById(R.id.share);
Intent i = getIntent();
userNameTxt = i.getStringExtra("user_name");
userName.setText(userNameTxt);
button = (Button)findViewById(R.id.image_pick);
image = (ImageView)findViewById(R.id.image);
gender_button();
category_button();
unit_button();
image_button();
share_button();
small_banner_ad();
final ParseQuery<ParseObject> query = ParseQuery.getQuery("profile_info");
// Restrict to cases where the author is the current user.
// Note that you should pass in a ParseUser and not the
// String reperesentation of that user
query.whereEqualTo("user_data", ParseUser.getCurrentUser());
// Run the query
query.findInBackground(new FindCallback<ParseObject>() {
public String TAG;
[user=439709]@override[/user]
public void done(List<ParseObject> postList, ParseException e) {
if (e == null) {
// If there are results, update the list of posts
// and notify the adapter
for (ParseObject profile_info : postList) {
userName.setText(profile_info.getString("user_name"));
fname.setText(profile_info.getString("first_name"));
lname.setText(profile_info.getString("last_name"));
hf.setText(profile_info.getString("height_in_feet"));
hi.setText(profile_info.getString("height_in_inches"));
weight.setText(profile_info.getString("weight"));
waist.setText(profile_info.getString("waist"));
wrist.setText(profile_info.getString("wrist"));
hip.setText(profile_info.getString("hip"));
forearm.setText(profile_info.getString("forearm"));
age.setText(profile_info.getString("age"));
gender.setText(profile_info.getString("gender"));
category.setText(profile_info.getString("category"));
unit.setText(profile_info.getString("unit"));
goal.setText(profile_info.getString("goal"));
}
} else {
Log.d("Post retrieval", "Error: " + e.getMessage());
}
}});
}
private void share_button()
{
share.setOnClickListener(new OnClickListener() {
public void onClick(View arg1) {
final ParseObject posts = new ParseObject("posts");
posts.put("user_name", userName.getText().toString());
posts.put("category", "My goal is to" + " "+category.getText()+" "+goal.getText()+" "+unit.getText().toString());
// Create an user data relationship with the current user
posts.put("user_posts", ParseUser.getCurrentUser());
// Save the post and return
posts.saveInBackground(new SaveCallback () {
[user=439709]@override[/user]
public void done(ParseException e) {
if (e == null) {
setResult(RESULT_OK);
Toast.makeText(getApplicationContext(),"post successfull",
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(),
"Error sharing: " + e.getMessage(),
Toast.LENGTH_SHORT)
.show();
}
}});
}
});
}
private void unit_button()
{
unit.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//Creating the instance of PopupMenu
PopupMenu popup = new PopupMenu(ProfilePage.this, unit);
//Inflating the Popup using xml file
if (category.getText().toString().equals("Loose Weight")){
popup.getMenuInflater()
.inflate(R.menu.weight_menu, popup.getMenu());
}if(category.getText().toString().equals("Target Weight")){
popup.getMenuInflater()
.inflate(R.menu.weight_menu, popup.getMenu());
}if(category.getText().toString().equals("Gain Weight")){
popup.getMenuInflater()
.inflate(R.menu.weight_menu, popup.getMenu());
}if(category.getText().toString().equals("Build Muscle")){
popup.getMenuInflater()
.inflate(R.menu.weight_menu, popup.getMenu());
}if(category.getText().toString().equals("Run")){
popup.getMenuInflater()
.inflate(R.menu.distance_menu, popup.getMenu());
}if(category.getText().toString().equals("Walk")){
popup.getMenuInflater()
.inflate(R.menu.distance_menu, popup.getMenu());
}
//registering popup with OnMenuItemClickListener
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.lbs:
//act for menu_item1
unit.setText("lbs");
return true;
case R.id.mile:
//act for sub_menu_item1
unit.setText("Mile");
return true;
case R.id.k:
//act for sub_menu_item1
unit.setText("K");
return true;
default:
//pass the event to parent, for options menu, use below
}
return false;
}
});
popup.show(); //showing popup menu
}
}); //closing the setOnClickListener method
}
private void category_button()
{
category.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//Creating the instance of PopupMenu
PopupMenu popup = new PopupMenu(ProfilePage.this, category);
//Inflating the Popup using xml file
popup.getMenuInflater()
.inflate(R.menu.category_menu, popup.getMenu());
//registering popup with OnMenuItemClickListener
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.target_weight:
category.setText("Target Weight");
return true;
case R.id.loose_weight:
//act for menu_item1
category.setText("Loose Weight");
return true;
case R.id. gain_weight:
//act for sub_menu_item1
category.setText("Gain Weight");
return true;
case R.id. build_muscle:
//act for sub_menu_item1
category.setText("Build Muscle");
return true;
case R.id. run:
//act for sub_menu_item1
category.setText("Run");
return true;
case R.id. walk:
//act for sub_menu_item1
category.setText("Walk");
return true;
default:
//pass the event to parent, for options menu, use below
}
return false;
}
});
popup.show(); //showing popup menu
}
}); //closing the setOnClickListener method
}
private void gender_button()
{
gender.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//Creating the instance of PopupMenu
PopupMenu popup = new PopupMenu(ProfilePage.this, gender);
//Inflating the Popup using xml file
popup.getMenuInflater()
.inflate(R.menu.gender_menu, popup.getMenu());
//registering popup with OnMenuItemClickListener
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id. male:
//act for menu_item1
gender.setText("Male");
return true;
case R.id. female:
//act for sub_menu_item1
gender.setText("Female");
return true;
default:
//pass the event to parent, for options menu, use below
}
return false;
}
});
popup.show(); //showing popup menu
}
}); //closing the setOnClickListener method
}
private void small_banner_ad()
{
AdView adView = (AdView) this.findViewById(R.id.adView);
//request TEST ads to avoid being disabled for clicking your own ads
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)// This is for emulators
//test mode on DEVICE (this example code must be replaced with your device uniquq ID)
.addTestDevice("15174709D5FCBF710958952E2589F20D") // Nexus 6
.build();
adView.loadAd(adRequest);
}
private void save_update_button()
{
ParseUser.getCurrentUser();
ParseQuery<ParseObject> pQuery = new ParseQuery<ParseObject>("profile_info");
pQuery.whereEqualTo("user_name", userName.getText().toString());
pQuery.getFirstInBackground(new GetCallback<ParseObject>()
{ [user=439709]@override[/user]
public void done(ParseObject update, ParseException e) {
if (e == null){
update.put("user_name", userName.getText().toString());
update.put("first_name", fname.getText().toString());
update.put("last_name", lname.getText().toString());
update.put("height_in_feet", hf.getText().toString());
update.put("height_in_inches", hi.getText().toString());
update.put("weight", weight.getText().toString());
update.put("waist", waist.getText().toString());
update.put("wrist", wrist.getText().toString());
update.put("hip", hip.getText().toString());
update.put("forearm", forearm.getText().toString());
update.put("age", age.getText().toString());
update.put("gender", gender.getText().toString());
update.put("category", category.getText().toString());
update.put("unit", unit.getText().toString());
update.put("goal", goal.getText().toString());
update.saveInBackground();
Toast.makeText(getApplicationContext(),
"Your profile has been updated",
Toast.LENGTH_SHORT)
.show();
} else {
final ParseObject profile_info = new ParseObject("profile_info");
profile_info.put("user_name", userNameTxt);
profile_info.put("first_name", fname.getText().toString());
profile_info.put("last_name", lname.getText().toString());
profile_info.put("height_in_feet", hf.getText().toString());
profile_info.put("height_in_inches", hi.getText().toString());
profile_info.put("weight", weight.getText().toString());
profile_info.put("waist", waist.getText().toString());
profile_info.put("wrist", wrist.getText().toString());
profile_info.put("hip", hip.getText().toString());
profile_info.put("forearm", forearm.getText().toString());
profile_info.put("age", age.getText().toString());
profile_info.put("gender", gender.getText().toString());
profile_info.put("category", category.getText().toString());
profile_info.put("unit", unit.getText().toString());
profile_info.put("goal", goal.getText().toString());
// Create an user data relationship with the current user
profile_info.put("user_data", ParseUser.getCurrentUser());
// Save the post and return
profile_info.saveInBackground(new SaveCallback () {
[user=439709]@override[/user]
public void done(ParseException e) {
if (e == null) {
setResult(RESULT_OK);
Toast.makeText(getApplicationContext(),"Profile saved",
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(),
"Error saving: " + e.getMessage(),
Toast.LENGTH_SHORT)
.show();
}
}});
}
}
});
}
//image button
public void image_button(){
image.setOnClickListener(new OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
// Create the Intent for Image Gallery.
Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
// Start new activity with the LOAD_IMAGE_RESULTS to handle back the results when image is picked from the Image Gallery.
startActivityForResult(i, LOAD_IMAGE_RESULTS);
}});
}
//menu [user=439709]@override[/user]
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.profile_menu, menu);
return super.onCreateOptionsMenu(menu);
}
[user=439709]@override[/user]
public boolean onOptionsItemSelected(MenuItem item) {
// The action bar home/up action should open or close the drawer.
// ActionBarDrawerToggle will take care of this.
// Handle action buttons
switch(item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
case R.id.logout:
ParseUser.logOut();
finish();
return true;
case R.id.Wall:
Intent intent = new Intent(ProfilePage.this,
Wall.class);
startActivity(intent);
return true;
case R.id.Save:
save_update_button();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
[user=439709]@override[/user]
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Here we need to check if the activity that was triggers was the Image Gallery.
// If it is the requestCode will match the LOAD_IMAGE_RESULTS value.
// If the resultCode is RESULT_OK and there is some data we know that an image was picked.
if (requestCode == LOAD_IMAGE_RESULTS && resultCode == RESULT_OK && data != null) {
// Let's read picked image data - its URI
Uri pickedImage = data.getData();
// Let's read picked image path using content resolver
String[] filePath = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(pickedImage, filePath, null, null, null);
cursor.moveToFirst();
String imagePath = cursor.getString(cursor.getColumnIndex(filePath[0]));
// Now we need to set the GUI ImageView data with data read from the picked file.
image.setImageBitmap(BitmapFactory.decodeFile(imagePath));
// At the end remember to close the cursor or you will end with the RuntimeException!
cursor.close();
}}}
[\CODE]
When I import "uri" for my on activity results at the end of my code I get a bunch of errors for everything I'm doing with parse. I been searching and trying different image picker tutorials and always end up with same results. I've checked out parse.com but only see info on saving images from the drawable folder. If I can get the image picker to work I'm pretty sure I can figure out how to save it to parse.com.
Sent from my Nexus 6 using XDA Free mobile app

Categories

Resources