Calls to resources after the Android project has been hit as a jar package.

Source: Internet
Author: User

The Android project cannot be packaged as a full jar package. This is mainly caused by R files, but we can put everything except the resource file into the jar package. Activity, view, and so on.

While providing a jar package, you also need to provide a resource file.

It is important to note that:

1. If the jar package contains activity, be sure to register it in the referenced project

2. If you have a resource file, you cannot use r .... Copy the resource file into the referenced project using the following class for conversion calls.

public class Mresource {
public static int Getidbyname (context context, string ClassName, string name) {
String PackageName = Context.getpackagename ();
Class r = null;
int id = 0;
try {
R = Class.forName (PackageName + ". R ");

        Class[] classes = r.getClasses();          Class desireClass = null;          for (int i = 0; i < classes.length; ++i) {              if (classes[i].getName().split("\\$")[1].equals(className)) {                  desireClass = classes[i];                  break;              }          }          if (desireClass != null)              id = desireClass.getField(name).getInt(desireClass);      } catch (ClassNotFoundException e) {          e.printStackTrace();      } catch (IllegalArgumentException e) {          e.printStackTrace();      } catch (SecurityException e) {          e.printStackTrace();      } catch (IllegalAccessException e) {          e.printStackTrace();      } catch (NoSuchFieldException e) {          e.printStackTrace();      }      return id;  }

}

 

From for notes (Wiz)

Calls to resources after the Android project is made into a jar package.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.