English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Share some small tricks for getting and changing package names in Android (very practical)

Introduction

Xiaocai often needs to modify the package name of a set of code many times due to work needs. Although it is not a technical task, Xiaocai has developed a little trick after using it many times and would like to share it with everyone. There will be no more words, let's take a detailed look at the introduction together.

The method is as follows:

      1. If the source code is on the local computer, first find the source code location, for example: change the package name from com.aaa.bbb to com.ccc.ddd, you can directly rename it, and make local modifications;

      2. Open this project in AndroidStudio;

      3. Delete .gradle;

      4. Replace appicationId in build.gradle with the new package name;

      5. sysn now, synchronize it;

      6. Edit -> Find -> Replace in Path... Replace all old package names with new ones

      7. Build -> Clean Project and the task is completed.

This method always works, everyone can try it out, make sure to delete the.gradle file~

Let me share another method to get all package names of mobile applications in android

Sample Code

public class Main3Activity extends AppCompatActivity { 
 private List<ResolveInfo> apps = new ArrayList<>(); 
 @Override 
 protected void onCreate(Bundle savedInstanceState) { 
 super.onCreate(savedInstanceState); 
 setContentView(R.layout.activity_main)3); 
 loadApps(); 
 } 
 private void loadApps() {}} 
 Intent intent = new Intent(Intent.ACTION_MAIN, null); 
 intent.addCategory(Intent.CATEGORY_LAUNCHER); 
 apps = getPackageManager().queryIntentActivities(intent, 0); 
 //Loop through the ResolveInfo object to get the package name and class name 
 for (int i = 0; i < apps.size(); i++) { 
  ResolveInfo info = apps.get(i); 
  String packageName = info.activityInfo.packageName; 
  CharSequence cls = info.activityInfo.name; 
  CharSequence name = info.activityInfo.loadLabel(getPackageManager()); 
  Log.e("ddddddd",name+"----"+packageName+"----"+cls); 
 } 
 } 
} 

Summary

That's all for this article. I hope the content of this article is of certain reference and learning value to everyone's learning or work. If you have any questions, you can leave a message for communication. Thank you for your support of the呐喊 tutorial.

Statement: The content of this article is from the network, and the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, has not been manually edited, and does not assume relevant legal liability. If you find any content suspected of copyright infringement, please send an email to: notice#w3Please report via email to codebox.com (replace # with @ when sending an email) and provide relevant evidence. Once verified, this site will immediately delete the infringing content.

You May Also Like