使用包管理器和广播打开没有启动器图标的应用程序

问题描述 投票:0回答:1

我想使用包管理器和广播打开一个没有启动器图标的应用程序。但是在我创建了一个包管理器并构建了应用程序之后,我的应用程序崩溃了。请帮助我。 我的主要活动代码:

导入android.app.Activity;

导入 android.app.*;

导入 android.os.*;

导入 android.view.*;

导入 android.view.View.*;

导入 android.widget.*;

导入 android.content.*;

导入 android.content.res.*;

导入 android.graphics.*;

导入 android.graphics.drawable.*;

导入 android.media.*;

导入 android.net.*;

导入 android.text.*;

导入 android.text.style.*;

导入 android.util.*;

导入 android.webkit.*;

导入 android.animation.*;

导入 android.view.animation.*;

导入java.io.*;

导入java.util.*;

导入 java.util.regex.*;

导入java.text.*;

导入org.json.*;

导入 android.widget.LinearLayout;

导入 android.widget.TextView;

导入 android.content.Intent;

导入 android.net.Uri;

导入 android.view.View;

导入android.app.Fragment;

导入 android.app.FragmentManager;

导入 android.app.DialogFragment;

导入 android.content.BroadcastReceiver;

公共类 MainActivity 扩展 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;


}

} `

我尝试为没有启动器图标的打开应用程序制作一个包管理器和广播

java android icons broadcast launcher
1个回答
0
投票
private PackageManager pm   = new PackageManager();

您无法以这种方式创建

PackageManager
的实例。相反,在
PackageManager
调用
getPackageManager()
之后的某个时间,通过在
Activity
上调用
super.onCreate()
来获取
onCreate()
实例。


将来,当您的应用程序崩溃时,请使用 Logcat 检查与崩溃相关的堆栈跟踪。如果您不理解堆栈跟踪,请将其包含在您的问题中。

© www.soinside.com 2019 - 2024. All rights reserved.