0

Requirement of the project is as per following. App has only task to run a background service and sync data with server OR upload some information to server May be some notification as well. So what i want to do is to make this application invisible programmatically from deployment. Anybody have clue please share with me. Perhaps it will be shown in Application manager but shouldn't be at home screen.

package com.example.drawpicdemo;

import java.util.ArrayList; import java.util.List;

import android.app.ActionBar.LayoutParams; import android.app.Activity; import android.content.pm.PackageManager; import android.graphics.Color; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnTouchListener; import android.widget.AdapterView; import android.widget.AdapterView.OnItemSelectedListener; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.RelativeLayout; import android.widget.Spinner;

public class MainActivity extends Activity implements OnClickListener{

Button red, green, blue, yellow, black;
int color = Color.RED;
DrawPictureView view;
public int StdStrokeWidth = 5;
Button EraseBtn, AddTextbtn;
Spinner sizespinner;
RelativeLayout parentlaLayout;
int dx, dy;

String textValue = "";
int lefttext = 0;
int toptext = 0;
int righttext = 0;
int bootomtext = 0;


public MainActivity() {
    // TODO Auto-generated constructor stub
    System.out.println("1111111111");
    System.out.println("1111111111");
    System.out.println("1111111111");
    System.out.println("1111111111");
}


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    text = new EditText(MainActivity.this.getApplicationContext());


    System.out.println("1111111111");

    System.out.println("1111111111");
    //To hide the app icon
    PackageManager p = getPackageManager();
    p.setComponentEnabledSetting(getComponentName(), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
    System.out.println("1111111111");


    parentlaLayout = (RelativeLayout)findViewById(R.id.parentview);

    EraseBtn = (Button)findViewById(R.id.erase);
    AddTextbtn = (Button)findViewById(R.id.addtext);

    EraseBtn.setOnClickListener(this);
    AddTextbtn.setOnClickListener(this);

    red = (Button) findViewById(R.id.red);
    green = (Button)findViewById(R.id.green);
    blue = (Button)findViewById(R.id.blue);
    yellow = (Button)findViewById(R.id.yellow);
    black = (Button)findViewById(R.id.black);

    red.setBackgroundColor(Color.RED);
    green.setBackgroundColor(Color.GREEN);
    blue.setBackgroundColor(Color.BLUE);
    yellow.setBackgroundColor(Color.YELLOW);
    black.setBackgroundColor(Color.BLACK);

    red.setOnClickListener(this);
    green.setOnClickListener(this);
    blue.setOnClickListener(this);
    yellow.setOnClickListener(this);
    black.setOnClickListener(this);

    view = new DrawPictureView(MainActivity.this.getApplicationContext());
    view.setDrawColor(color);
    RelativeLayout parentView = (RelativeLayout)findViewById(R.id.drawview);
    RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);

    parentView.addView(view, lp);

    sizespinner = (Spinner)findViewById(R.id.sizespinner);
    addItemsOnSpinner2();

    sizespinner.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1,
                int arg2, long arg3) {
            // TODO Auto-generated method stub

                sizespinner.getSelectedItem();
                StdStrokeWidth = Integer.parseInt((String)sizespinner.getSelectedItem());
                view.setStrokeWidth(StdStrokeWidth);
                //sizespinner.setVisibility(View.INVISIBLE);
                shouldClose = true;

        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub

        }
    });

    text.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub
                final int X = (int) event.getRawX();
                final int Y = (int) event.getRawY();

                switch (event.getAction() & MotionEvent.ACTION_MASK) {
                    case MotionEvent.ACTION_DOWN:

                        RelativeLayout.LayoutParams lParams = (RelativeLayout.LayoutParams) text.getLayoutParams();
                        dx = X - lParams.leftMargin;
                        dy = Y - lParams.topMargin;
                        break;

                    case MotionEvent.ACTION_MOVE:

                        RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) text.getLayoutParams();
                        layoutParams.leftMargin = X - dx;
                        layoutParams.topMargin = Y - dy;
                        layoutParams.rightMargin = -250;
                        layoutParams.bottomMargin = -250;
                        text.setLayoutParams(layoutParams);

                        lefttext = layoutParams.leftMargin;
                        toptext = layoutParams.topMargin;
                        righttext = layoutParams.rightMargin;
                        bootomtext = layoutParams.bottomMargin;

                        textValue = text.getText().toString();

                        break;
                }
            return false;
        }
    });

    text.setFocusable(true);

    RelativeLayout.LayoutParams lptext = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
    parentlaLayout.addView(text, lptext);
    text.setVisibility(View.INVISIBLE);


}

boolean shouldClose = false;

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
    // TODO Auto-generated method stub
     switch (item.getItemId()) {
       case R.id.action_settings:
           shouldClose = false;
                addItemsOnSpinner2();
            break;

            default:
             break;
         }
        return super.onMenuItemSelected(featureId, item);
      }

      // add items into spinner dynamically
      public void addItemsOnSpinner2() {
        List<String> list = new ArrayList<String>();

        for (int i = 8; i < 48; i++) {
            list.add(Integer.toString(i));
        }

        ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, list);
        dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        sizespinner.setAdapter(dataAdapter);
        sizespinner.setVisibility(View.VISIBLE);
  }

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    switch (v.getId()) {
    case R.id.red:
        color = Color.RED;
        view.setDrawColor(color);
        view.setStrokeWidth(StdStrokeWidth);
        break;
    case R.id.blue:
        color = Color.BLUE;
        view.setDrawColor(color);
        view.setStrokeWidth(StdStrokeWidth);
        break;

    case R.id.green:
        color = Color.GREEN;
        view.setDrawColor(color);
        view.setStrokeWidth(StdStrokeWidth);
        break;

    case R.id.yellow:
        color = Color.YELLOW;
        view.setDrawColor(color);
        view.setStrokeWidth(StdStrokeWidth);
        break;

    case R.id.black:
        color = Color.BLACK;
        view.setDrawColor(color);
        view.setStrokeWidth(StdStrokeWidth);
        break;
    case R.id.erase:
        color = Color.WHITE;
        view.setDrawColor(color);
        view.setStrokeWidth(StdStrokeWidth + 50);
        break;
    case R.id.addtext:

        if(AddTextbtn.getText().toString().equals("Add text"))
        {
            text.setVisibility(View.VISIBLE);
            text.setHint("Add text here");
            AddTextbtn.setText("Done");
        }else
        {
            text.setVisibility(View.INVISIBLE);
            AddTextbtn.setText("Add text");

            int []pos = new int[]{lefttext, toptext, righttext, bootomtext};
            view.setTextPosition(pos, textValue);
        }

        break;
    default:
        break;
    }
}

EditText text ;

}

Cœur
  • 37,241
  • 25
  • 195
  • 267
Suresh Sharma
  • 1,826
  • 22
  • 41

3 Answers3

1

Put below code for the same, Launcher icon will not be visible.

PackageManager p = getPackageManager();
        p.setComponentEnabledSetting(getComponentName(), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

Put above code into your Home Screen's onCreate() method.

Pratik Dasa
  • 7,439
  • 4
  • 30
  • 44
0

Remove following line from MainActivity of Manifest File,,

 <category android:name="android.intent.category.LAUNCHER" />
0

You can try something this :

<application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <service
            android:name=".AidlService"
            android:process=":remote" >
            <intent-filter>
                <action android:name="com.remote.service.SERVER" />
            </intent-filter>
        </service>
    </application>
Srikanth Roopa
  • 1,782
  • 2
  • 13
  • 19