• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps barcode and qr code programming

Hi i changed up the create class. its definitely giving me what I want, but I now I want to low when i want to create or save a file inside my app into a folder how do i do that? Thanks

Code:
import android.app.Activity;

import android.app.AlertDialog;

import android.content.DialogInterface;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.Toast;



public class Create extends Activity {

    /** Called when the activity is first created. */

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_create);



        Button btnAlert = (Button) findViewById(R.id.btnAlert);

        Button btnAlertTwoBtns = (Button) findViewById(R.id.btnAlertWithTwoBtns);

        Button btnAlertThreeBtns = (Button) findViewById(R.id.btnAlertWithThreeBtns);



        btnAlert.setOnClickListener(new View.OnClickListener() {



            public void onClick(View arg0) {

                // Creating alert Dialog with one Button



                AlertDialog alertDialog = new AlertDialog.Builder(

                        Create.this).create();



                // Setting Dialog Title

                alertDialog.setTitle("Alert Dialog");



                // Setting Dialog Message

                alertDialog.setMessage("Welcome to AndroidHive.info");



                // Setting Icon to Dialog

                //alertDialog.setIcon(R.drawable.tick);



                // Setting OK Button

                alertDialog.setButton("OK",

                        new DialogInterface.OnClickListener() {



                            public void onClick(DialogInterface dialog,

                                    int which) {

                                // Write your code here to execute after dialog

                                // closed

                                Toast.makeText(getApplicationContext(),

                                        "You clicked on OK", Toast.LENGTH_SHORT)

                                        .show();

                            }

                        });



                // Showing Alert Message

                alertDialog.show();



            }

        });



        /**

        * Showing Alert Dialog with Two Buttons one Positive Button with Label

        * "YES" one Negative Button with Label "NO"

        */

        btnAlertTwoBtns.setOnClickListener(new View.OnClickListener() {



            public void onClick(View arg0) {

                // Creating alert Dialog with two Buttons



                AlertDialog.Builder alertDialog = new AlertDialog.Builder(Create.this);



                // Setting Dialog Title

                alertDialog.setTitle("Confirm Delete...");



                // Setting Dialog Message

                alertDialog.setMessage("Are you sure you want delete this?");



                // Setting Icon to Dialog

                //alertDialog.setIcon(R.drawable.delete);



                // Setting Positive "Yes" Button

                alertDialog.setPositiveButton("YES",

                        new DialogInterface.OnClickListener() {

                            public void onClick(DialogInterface dialog,int which) {

                                // Write your code here to execute after dialog

                                Toast.makeText(getApplicationContext(), "You clicked on YES", Toast.LENGTH_SHORT).show();

                            }

                        });

                // Setting Negative "NO" Button

                alertDialog.setNegativeButton("NO",

                        new DialogInterface.OnClickListener() {

                            public void onClick(DialogInterface dialog,    int which) {

                                // Write your code here to execute after dialog

                                Toast.makeText(getApplicationContext(), "You clicked on NO", Toast.LENGTH_SHORT).show();

                                dialog.cancel();

                            }

                        });



                // Showing Alert Message

                alertDialog.show();



            }

        });



        /**

        * Showing Alert Dialog with Two Buttons one Positive Button with Label

        * "YES" one Neutral Button with Label "NO" one Negative Button with

        * label "Cancel"

        */

        btnAlertThreeBtns.setOnClickListener(new View.OnClickListener() {



            public void onClick(View arg0) {

                // Creating alert Dialog with three Buttons



                AlertDialog.Builder alertDialog = new AlertDialog.Builder(

                        Create.this);



                // Setting Dialog Title

                alertDialog.setTitle("Save File...");



                // Setting Dialog Message

                alertDialog.setMessage("Do you want to save this file?");



                // Setting Icon to Dialog

                //alertDialog.setIcon(R.drawable.save);



                // Setting Positive Yes Button

                alertDialog.setPositiveButton("YES",

                        new DialogInterface.OnClickListener() {



                            public void onClick(DialogInterface dialog,

                                    int which) {

                                // User pressed Cancel button. Write Logic Here

                                Toast.makeText(getApplicationContext(),

                                        "You clicked on YES",

                                        Toast.LENGTH_SHORT).show();

                            }

                        });

                // Setting Positive Yes Button

                alertDialog.setNeutralButton("NO",

                        new DialogInterface.OnClickListener() {



                            public void onClick(DialogInterface dialog,

                                    int which) {

                                // User pressed No button. Write Logic Here

                                Toast.makeText(getApplicationContext(),

                                        "You clicked on NO", Toast.LENGTH_SHORT)

                                        .show();

                            }

                        });

                // Setting Positive "Cancel" Button

                alertDialog.setNegativeButton("Cancel",

                        new DialogInterface.OnClickListener() {



                            public void onClick(DialogInterface dialog,

                                    int which) {

                                // User pressed Cancel button. Write Logic Here

                                Toast.makeText(getApplicationContext(),

                                        "You clicked on Cancel",

                                        Toast.LENGTH_SHORT).show();

                            }

                        });

                // Showing Alert Message

                alertDialog.show();



            }

        });

    }

}


Code:
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:orientation="vertical"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent">

   

    <Button android:id="@+id/btnAlert"

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:text="Show Alert"

            android:padding="10dip"

            android:layout_marginTop="40dip">

    </Button>

   

    <Button android:id="@+id/btnAlertWithTwoBtns"

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:text="Show Alert With Two Buttons"

            android:padding="10dip">

    </Button>

   

    <Button android:id="@+id/btnAlertWithThreeBtns"

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:text="Show Alert with Three Buttons"

            android:padding="10dip">

    </Button>

</LinearLayout>
 
Upvote 0
Upvote 0
If you want to know how to create files and folders, there are many web resources with good information explaining how to do this. Rather than regurgitate that information here, I'll just post a few useful links. There are many more:

https://developer.android.com/training/basics/data-storage/files.html
http://www.tutorialspoint.com/android/android_internal_storage.htm
http://www.java-samples.com/showtutorial.php?tutorialid=1523

are there other links you know of. I used some of them and they gave me what I wanted. Now i just want to know how to save it under device storage for my android under the download section. Are there any links for that?
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones