Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Content providers #2200

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/source/buildoptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ options (this list may not be exhaustive):
include multiple jar files, pass this argument multiple times.
- ``--intent-filters``: A file path containing intent filter xml to be
included in AndroidManifest.xml.
- ``--content-providers``: A file path containing provider xml to be
included in AndroidManifest.xml.
- ``--service``: A service name and the Python script it should
run. See :ref:`arbitrary_scripts_services`.
- ``--add-source``: Add a source directory to the app's Java code.
Expand Down
22 changes: 22 additions & 0 deletions pythonforandroid/bootstraps/common/build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,10 @@ def make_package(args):
with open(args.intent_filters) as fd:
args.intent_filters = fd.read()

if args.content_providers:
with open(args.content_providers) as f:
args.content_providers = f.read()

if not args.add_activity:
args.add_activity = []

Expand Down Expand Up @@ -507,6 +511,14 @@ def make_package(args):
join(res_dir, 'values/strings.xml'),
**render_args)

# extra xml resources
if args.add_xml_resource:
xml_res_dir = join(res_dir, 'xml')
if not exists(xml_res_dir):
os.mkdir(xml_res_dir)
for file_path in args.add_xml_resource:
shutil.copy(file_path, join(xml_res_dir, basename(file_path)))

if exists(join("templates", "custom_rules.tmpl.xml")):
render(
'custom_rules.tmpl.xml',
Expand Down Expand Up @@ -707,6 +719,16 @@ def parse_args_and_make_package(args=None):
'filename containing xml. The filename should be '
'located relative to the python-for-android '
'directory'))
ap.add_argument('--content-providers', dest='content_providers',
help=('Add providers xml rules to the '
'AndroidManifest.xml file. The argument is a '
'filename containing xml. The filename should be '
'located relative to the python-for-android '
'directory'))
ap.add_argument('--add-xml-resource', dest='add_xml_resource',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't we add something else recently for moving stuff into the src/main/res folder?
I'm wondering if what we really want is a generic "copy this file/folder into src/main/res" argument, rather than many arguments for different subfolders.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I can replace it with a more generic argument to copy files/directories into src/main/res.

action='append',
help=('Copy this file to the src/main/res/xml '
'subdirectory of the build.'))
ap.add_argument('--with-billing', dest='billing_pubkey',
help='If set, the billing service will be added (not implemented)')
ap.add_argument('--add-source', dest='extra_source_dirs', action='append',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,14 @@
</intent-filter>
</receiver>
{% endif %}
{% for a in args.add_activity %}
<activity android:name="{{ a }}"></activity>
{% endfor %}

{% for a in args.add_activity %}
<activity android:name="{{ a }}"></activity>
{% endfor %}

{%- if args.content_providers -%}
{{- args.content_providers -}}
{%- endif -%}
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@
</intent-filter>
</receiver>
{% endif %}

{%- if args.content_providers -%}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why {%- rather than just {% (and same elsewhere)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No other reason apart from not being familiar with Jinja and copy-pasting the lines that render the intent filters. I will fix it.

{{- args.content_providers -}}
{%- endif -%}
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@
</intent-filter>
</receiver>
{% endif %}

{%- if args.content_providers -%}
{{- args.content_providers -}}
{%- endif -%}
</application>

</manifest>