javaandroidiconsbroadcastlauncher

Open app without Launcher icon with package Manager and Broadcast


I want open a app without Launcher icon with Package Manager and Broadcast. But After me make a package Manager and after I builded app my app is crashed. Plz help me. My Main activity code:

import android.app.Activity;

import android.app.*;

import android.os.*;

import android.view.*;

import android.view.View.*;

import android.widget.*;

import android.content.*;

import android.content.res.*;

import android.graphics.*;

import android.graphics.drawable.*;

import android.media.*;

import android.net.*;

import android.text.*;

import android.text.style.*;

import android.util.*;

import android.webkit.*;

import android.animation.*;

import android.view.animation.*;

import java.io.*;

import java.util.*;

import java.util.regex.*;

import java.text.*;

import org.json.*;

import android.widget.LinearLayout;

import android.widget.TextView;

import android.content.Intent;

import android.net.Uri;

import android.view.View;

import android.app.Fragment;

import android.app.FragmentManager;

import android.app.DialogFragment;

import android.content.BroadcastReceiver;

public class MainActivity extends Activity {

private LinearLayout linear1;


private LinearLayout linear2;


private TextView textview2;


private TextView textview3;





private Intent xnnzm = new Intent();


private Intent content = new Intent();


private Intent context = new Intent();

private PackageManager pm   = new PackageManager();





@Override


protected void onCreate(Bundle _savedInstanceState) {


    super.onCreate(_savedInstanceState);


    setContentView(R.layout.main);


    initialize(_savedInstanceState);


    initializeLogic();


}





private void initialize(Bundle _savedInstanceState) {


    linear1 = findViewById(R.id.linear1);


    linear2 = findViewById(R.id.linear2);


    textview2 = findViewById(R.id.textview2);


    textview3 = findViewById(R.id.textview3);


    


    linear2.setOnClickListener(new View.OnClickListener() {


        @Override


        public void onClick(View _view) {


            xnnzm.setClass(getApplicationContext(), MainActivity.class);


            startActivity(xnnzm);


        }


    });


}





private void initializeLogic() {


}








@Deprecated


public void showMessage(String _s) {


    Toast.makeText(getApplicationContext(), _s, Toast.LENGTH_SHORT).show();


}





@Deprecated


public int getLocationX(View _v) {


    int _location[] = new int[2];


    _v.getLocationInWindow(_location);


    return _location[0];


}





@Deprecated


public int getLocationY(View _v) {


    int _location[] = new int[2];


    _v.getLocationInWindow(_location);


    return _location[1];


}





@Deprecated


public int getRandom(int _min, int _max) {


    Random random = new Random();


    return random.nextInt(_max - _min + 1) + _min;


}





@Deprecated


public ArrayList<Double> getCheckedItemPositionsToArray(ListView _list) {


    ArrayList<Double> _result = new ArrayList<Double>();


    SparseBooleanArray _arr = _list.getCheckedItemPositions();


    for (int _iIdx = 0; _iIdx < _arr.size(); _iIdx++) {


        if (_arr.valueAt(_iIdx))


        _result.add((double)_arr.keyAt(_iIdx));


    }


    return _result;


}





@Deprecated


public float getDip(int _input) {


    return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, _input, getResources().getDisplayMetrics());


}





@Deprecated


public int getDisplayWidthPixels() {


    return getResources().getDisplayMetrics().widthPixels;


}





@Deprecated


public int getDisplayHeightPixels() {


    return getResources().getDisplayMetrics().heightPixels;


}

} `

I try to made a Package Manager and Broadcast for open App without Launcher icon


Solution

  • private PackageManager pm   = new PackageManager();
    

    You cannot create an instance of PackageManager that way. Instead, get a PackageManager instance by calling getPackageManager() on your Activity, sometime after the super.onCreate() call in onCreate().


    In the future, when your app crashes, please use Logcat to examine the stack trace associated with the crash. If you do not understand the stack trace, include it in your question.