6
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

DelphiAdvent Calendar 2020

Day 7

Androidで起動時、deplhiで作成したアプリを自動起動にする。

Last updated at Posted at 2020-12-07

delphi 2020 アドベントカレンダー 7日目です

こんにちは
やましょうです。

#Delphiで作ったアプリをAndroid起動時に自動起動。

##1.まず検索

1.classes.dexを入れ替えてパッケージを作る方法
https://dannywind.nl/auto-start-delphi-xe5-android-app-after-boot/

2.jar ファイルを自分でつくる方法
https://blog.csdn.net/tanqth/article/details/74357209
お金で解決がここは中華口座が必要。

結果jarファイルで行う方が無難だと思う。

##2.javaでソースを仕方なく書く

BootReceiver.java
package com.qa65000;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.Context;
import android.util.Log;

public class BootReceiver extends BroadcastReceiver
{

    @Override
    public void onReceive(Context context, Intent intent) 
    {
	        Log.d("test_TAG", "onRecive()");
        if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
            Log.d("test_TAG", "Booo........t Complated()");
            Intent launchIntent = new Intent();
			launchIntent.setClassName(context, "com.embarcadero.firemonkey.FMXNativeActivity");           
            launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
           	context.startActivity(launchIntent);  
        }
	}
}

~~~

##3.batファイルを作ってコンパイルする
~~~
echo.
echo Compiles your Java code into classes.dex
echo Verified to work for Delphi XE6
echo.
echo Place this batch in a java folder below your project (project\java)
echo Place the source in project\java\src\com\dannywind\delphi
echo If your source file location or name is different, please modify it below.
echo This assumes a Win64 system with the 64-bit Java installed by the Delphi XE6 
echo installer in C:\Program Files\Java\jdk1.70.0_25
echo.

setlocal
                 
set ANDROID_JAR="C:\Users\Public\Documents\Embarcadero\Studio\20.0\PlatformSDKs\android-sdk-windows\platforms\android-26\android.jar"
set DX_LIB="C:\Users\Public\Documents\Embarcadero\Studio\20.0\PlatformSDKs\android-sdk-windows\build-tools\28.0.2\lib"
set EMBO_DEX="C:\Program Files (x86)\Embarcadero\Studio\20.0\lib\android\debug\classes.dex"
set PROJ_DIR=%CD%
set VERBOSE=0
set JAVASDK="C:\Program Files\Java\jdk1.8.0_60\bin"
set DX_BAT="C:\Users\Public\Documents\Embarcadero\Studio\20.0\PlatformSDKs\android-sdk-windows\build-tools\28.0.2\dx.bat"

echo.
echo Compiling the Java source files
echo.
pause
mkdir output 2> nul
mkdir output\classes 2> nul
if x%VERBOSE% == x1 SET VERBOSE_FLAG=-verbose
%JAVASDK%\javac %VERBOSE_FLAG% -classpath %ANDROID_JAR% -d    bin\classes src\com\qa65000\BootReceiver.java
%JAVASDK%\javac %VERBOSE_FLAG% -classpath %ANDROID_JAR% -d output\classes src\com\qa65000\BootReceiver.java

jar cvf bin\BootReceiver.jar -C bin\classes jp

echo. ここから不要だと思う(classes.dexを書き換える場合のコンパイル)
echo Creating jar containing the new classes
echo.
pause
mkdir output\jar 2> nul
if x%VERBOSE% == x1 SET VERBOSE_FLAG=v
%JAVASDK%\jar c%VERBOSE_FLAG%f output\jar\test_classes.jar -C output\classes com

echo.
echo Converting from jar to dex...
echo.
pause

mkdir output\dex 2> nul
if x%VERBOSE% == x1 SET VERBOSE_FLAG=--verbose
call %DX_BAT% --dex %VERBOSE_FLAG% --output=%PROJ_DIR%\output\dex\test_classes.dex --positions=lines %PROJ_DIR%\output\jar\test_classes.jar

echo.
echo Merging dex files
echo.
pause
%JAVASDK%\java -cp %DX_LIB%\dx.jar com.android.dx.merge.DexMerger %PROJ_DIR%\output\dex\classes.dex %PROJ_DIR%\output\dex\test_classes.dex %EMBO_DEX%
echo.
echo Now use output\dex\classes.dex instead of default classes.dex
echo And add broadcastreceiver to AndroidManifest.template.xml
echo.

:Exit

endlocal


                                      javac -classpath "C:\Users\Public\Documents\Embarcadero\Studio\15.0\PlatformSDKs\adt-bundle-windows-x86-20131030\sdk\platforms\android-19\android.jar" -d bin\classes src\com\example\hello\Hello.java

C:\Program Files\Java\jdk1.8.0_60\bin"\javac  -Xlint:all -class
~~~


##4.作成したBootReciver.jarをプロジェクトに追加する
(10.3で64bitは追加できない

![SnapCrab_NoName_2020-12-7_20-3-8_No-00.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/31412/429ff923-d593-7ee7-bf5e-15b4c8eb484f.png)

##.5 コンパイルして転送する
たぶん動くと思う夏にやった奴なのでうごかなかったらごめんなさいです。)


本家のコードが
一応気になる人は
https://www.youtube.com/watch?v=4_CkU9L2mCo&t=173s
をみてください

以上
やましょうでした
6
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?