Thread: Android app

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2016
    Posts
    1
    Rep Power
    0

    Smile Android app


    Hi i am making a caregiver app and made modifications with the code. What I am trying to do is link buttons to a file. When i click the create button it should ask me how many lies to create and I should be able to name the files in the create button category. How do I program that? Then for scan i right now have it doing something temporarily different but when I click scan inside the scan button 3 button options should show up which are barcode, qrcode and image. How do i link those 3 buttons inside the scan button category? Thank you for your help.
    Code:
    import com.example.Caregiver.R;
    
    import android.app.Activity;
    
    import android.app.AlertDialog;
    
    import android.content.ActivityNotFoundException;
    
    import android.content.DialogInterface;
    
    import android.content.Intent;
    
    import android.graphics.Bitmap;
    
    import android.graphics.BitmapFactory;
    
    import android.graphics.drawable.Drawable;
    
    import android.net.Uri;
    
    import android.os.Bundle;
    
    import android.provider.MediaStore;
    
    import android.util.Log;
    
    import android.view.Gravity;
    
    import android.view.Menu;
    
    import android.view.MenuInflater;
    
    import android.view.MenuItem;
    
    import android.view.View;
    
    import android.view.View.OnClickListener;
    
    import android.widget.Button;
    
    import android.widget.ImageView;
    
    import android.widget.TextView;
    
    import android.widget.Toast;
    
    import java.io.File;
    
    import android.graphics.drawable.BitmapDrawable;
    
    import android.graphics.drawable.Drawable; 
    
    
    
    public class MainActivity extends Activity {
    
    
    
    static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 100; 
    
    static final String ACTION_SCAN = "com.google.zxing.client.android.SCAN";
    
    private Uri fileUri;
    
    
    
    
    
    
    
    @override
    
    protected void onCreate(Bundle savedInstanceState) {
    
    super.onCreate(savedInstanceState);
    
    setContentView(R.layout.activity_main);
    
    }
    
    @override
    
    public boolean onCreateOptionsMenu(Menu menu) {
    
    MenuInflater inflater = getMenuInflater();
    
    inflater.inflate(R.menu.testmenu, menu);
    
    return true;
    
    }
    
    
    
    @override
    
    public boolean onOptionsItemSelected(MenuItem item){
    
    super.onOptionsItemSelected(item);
    
    switch(item.getItemId()){
    
    case R.id.Create:
    
    CreateMenuItem();
    
    break;
    
    case R.id.scan:
    
    scanMenuItem();
    
    break;
    
    case R.id.View:
    
    ViewMenuItem();
    
    break;
    
    }
    
    return true;
    
    }
    
    private void CreateMenuItem(){
    
    new AlertDialog.Builder(this)
    
    .setTitle("Create")
    
    .setMessage("This is a create dialog")
    
    .setNeutralButton("OK", new DialogInterface.OnClickListener() {
    
    
    
    @override
    
    public void onClick(DialogInterface dialog, int which) {
    
    // TODO Auto-generated method stub
    
    
    
    }
    
    }).show();
    
    }
    
    
    
    private void scanMenuItem(){
    
    try{
    
    Intent intent = new Intent(ACTION_SCAN);
    
    intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
    
    startActivityForResult(intent, 0);
    
    }catch (ActivityNotFoundException e){
    
    showDialog(MainActivity.this, "No Scanner Found", 
    
    "Download a scanner code activity?", "Yes", "No").show();
    
    }
    
    }
    
    
    
    private void ViewMenuItem(){
    
    new AlertDialog.Builder(this)
    
    .setTitle("View")
    
    .setMessage("This is a dialog")
    
    .setNeutralButton("OK", new DialogInterface.OnClickListener() {
    
    
    
    @override
    
    public void onClick(DialogInterface dialog, int which) {
    
    // TODO Auto-generated method stub
    
    
    
    }
    
    }).show();
    
    }
    
    
    
    public void scanBar(View v){
    
    try{
    
    Intent intent = new Intent(ACTION_SCAN);
    
    intent.putExtra("SCAN_MODE", "PRODUCT_MODE");
    
    startActivityForResult(intent, 0);
    
    }catch (ActivityNotFoundException e){
    
    showDialog(MainActivity.this, "No Scanner Found", 
    
    "Download a scanner code activity?", "Yes", "No").show();
    
    
    
    }
    
    
    
    
    
    }
    
    
    
    public void scanQR(View v){
    
    try{
    
    Intent intent = new Intent(ACTION_SCAN);
    
    intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
    
    startActivityForResult(intent, 0);
    
    }catch (ActivityNotFoundException e){
    
    showDialog(MainActivity.this, "No Scanner Found", 
    
    "Download a scanner code activity?", "Yes", "No").show();
    
    }
    
    } 
    
    
    
    public void Camera(View v){
    
    try{
    
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    
    //fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
    
    intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
    
    startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
    
    }catch (ActivityNotFoundException e){
    
    
    
    }
    
    }
    
    
    
    private static AlertDialog showDialog(final Activity act,
    
    CharSequence title, CharSequence message, 
    
    CharSequence buttonYes,
    
    CharSequence buttonNo) {
    
    
    
    AlertDialog.Builder dowloadDialog = new AlertDialog.Builder(act);
    
    dowloadDialog.setTitle(title).setMessage(message).setPositiveButton(buttonYes, new DialogInterface.OnClickListener() {
    
    
    
    @override
    
    public void onClick(DialogInterface dialog, int which) {
    
    Uri uri = Uri.parse("market://search?q=pname:" +
    
    "com.google.zxing.client.android");
    
    
    
    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    
    try{
    
    act.startActivity(intent);
    
    } catch(ActivityNotFoundException e){
    
    
    
    }
    
    
    
    }
    
    }).setNegativeButton(buttonNo, new DialogInterface.OnClickListener() {
    
    
    
    @override
    
    public void onClick(DialogInterface dialog, int which) {
    
    
    
    
    
    }
    
    });
    
    
    
    return dowloadDialog.show();
    
    
    
    }
    
    
    
    protected void onActivityResult1(int requestCode, int resultCode, Intent data) {
    
    if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
    
    if (resultCode == RESULT_OK) {
    
    // Image captured and saved to fileUri specified in the Intent
    
    Toast.makeText(this, "Image saved to:\n" +
    
    data.getData(), Toast.LENGTH_LONG).show();
    
    } else if (resultCode == RESULT_CANCELED) {
    
    // User cancelled the image capture
    
    
    
    } else {
    
    // Image capture failed, advise user
    
    }
    
    }
    
    }
    
    
    
    @override
    
    protected void onActivityResult(int requestCode, int resultCode, Intent intent){
    
    if(requestCode == 0){
    
    if(resultCode == RESULT_OK){
    
    String contents = intent.getStringExtra("SCAN_RESULT");
    
    String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
    
    Toast.makeText(this, "Content:" + contents + "Format:" + format,
    
    Toast.LENGTH_LONG).show();
    
    
    
    } else if (resultCode == RESULT_CANCELED) {
    
    // Handle cancel
    
    Toast toast = Toast.makeText(this, "Scan was Cancelled!", Toast.LENGTH_LONG);
    
    toast.setGravity(Gravity.TOP, 25, 400);
    
    toast.show();
    
    
    
    }
    
    }
    
    }
    
    }
    
    activity_main.xml
    <?xml version="1.0" encoding="utf-8"?>
    
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    
    xmlns:tools="http://schemas.android.com/tools"
    
    android:id="@+id/container"
    
    android:layout_width="match_parent"
    
    android:layout_height="match_parent"
    
    android:background="#ffffff"
    
    android:backgroundTint="@android:color/holo_blue_bright"
    
    android:foregroundTint="@android:color/holo_red_light"
    
    android:eek:rientation="vertical"
    
    tools:context="com.javacodegeeks.androidstartactivityforresultexample.ActivityOne" >
    
    
    
    <TextView
    
    android:id="@+id/textView1"
    
    android:layout_width="wrap_content"
    
    android:layout_height="wrap_content"
    
    android:layout_gravity="center|top"
    
    android:layout_margin="20dp"
    
    android:text="Scan"
    
    android:textColor="#000000"
    
    android:textSize="30dp" />
    
    
    
    
    
    <Button
    
    android:id="@+id/scanner"
    
    android:layout_width="250dp"
    
    android:layout_height="80dp"
    
    android:layout_gravity="center"
    
    android:layout_margin="10dp"
    
    android:backgroundTint="@android:color/holo_purple"
    
    android:gravity="center"
    
    android:eek:nClick="Create"
    
    android:text="Create"
    
    android:textSize="18dp" />
    
    
    
    <Button
    
    android:id="@+id/scanner1"
    
    android:layout_width="250dp"
    
    android:layout_height="80dp"
    
    android:layout_gravity="center"
    
    android:layout_margin="10dp"
    
    android:backgroundTint="@android:color/holo_orange_dark"
    
    android:gravity="center"
    
    android:eek:nClick="scanQR"
    
    android:text="Scan"
    
    android:textSize="18dp" />
    
    
    
    
    
    
    
    
    
    <!-- <Button -->
    
    <!-- android:id="@+id/scanner1" -->
    
    <!-- android:layout_width="250dp" -->
    
    <!-- android:layout_height="80dp" -->
    
    <!-- android:layout_gravity="center" -->
    
    <!-- android:layout_margin="10dp" -->
    
    <!-- android:backgroundTint="@android:color/holo_orange_dark" -->
    
    <!-- android:gravity="center" -->
    
    <!-- android:eek:nClick="scanQR" -->
    
    <!-- android:text="QR Code" -->
    
    <!-- android:textSize="18dp" /> -->
    
    
    
    
    
    
    
    <!-- <Button -->
    
    <!-- android:id="@+id/scanner2" -->
    
    <!-- android:layout_width="250dp" -->
    
    <!-- android:layout_height="80dp" -->
    
    <!-- android:layout_gravity="center" -->
    
    <!-- android:layout_margin="10dp" -->
    
    <!-- android:backgroundTint="@android:color/holo_purple" -->
    
    <!-- android:gravity="center" -->
    
    <!-- android:eek:nClick="scanBar" -->
    
    <!-- android:text="Bar Code" -->
    
    <!-- android:textSize="18dp" /> -->
    
    
    
    
    
    
    
    <Button
    
    android:id="@+id/scanner2"
    
    android:layout_width="250dp"
    
    android:layout_height="80dp"
    
    android:layout_gravity="center"
    
    android:layout_margin="10dp"
    
    android:backgroundTint="@android:color/holo_red_dark"
    
    android:gravity="center"
    
    android:eek:nClick="Camera"
    
    android:text="Image"
    
    android:textSize="18dp" >
    
    
    
    </Button>
    
    
    
    <Button
    
    android:id="@+id/scanner3"
    
    android:layout_width="250dp"
    
    android:layout_height="80dp"
    
    android:layout_gravity="center"
    
    android:layout_margin="10dp"
    
    android:backgroundTint="@android:color/holo_blue_dark"
    
    android:gravity="center"
    
    android:eek:nClick="View"
    
    android:text="View"
    
    android:textSize="18dp" >
    
    
    
    </Button> 
    
    
    
    
    
    
    
    </LinearLayout>
    
    
    testmenu:
    
    
    <menu xmlns:android="http://schemas.android.com/apk/res/android">
    
    <item 
    
    android:id="@+id/Create"
    
    android:title="Create"
    
    android:eek:rderInCategory="1"
    
    android:showAsAction="ifRoom"/>
    
    
    
    <item 
    
    android:id="@+id/scan"
    
    android:title="Scan" 
    
    android:eek:rderInCategory="2"
    
    android:showAsAction="never"/>
    
    
    
    <item 
    
    android:id="@+id/View"
    
    android:title="View" 
    
    android:OrderInCategory="3"
    
    android:showAsAction="never"/>
    
    
    
    
    
    </menu>
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2017
    Posts
    1
    Rep Power
    0
    Recently I saw an Android tv app that was specially built for promotion for alcoholic beverages. What will be the cost and how much time will take for making these kinds of Android tv apps.
    See here. https://www.rootinfosol.com/android-tv-app-development

IMN logo majestic logo threadwatch logo seochat tools logo