[英]Start FtpServer when charging the Phone
i want to make an App which starts an FTPServer when my Phone is conncted to Power. 我想制作一个当我的手机连接到电源时启动FTPServer的应用程序。 I dont want my App to have an GUI.
我不希望我的应用程序具有GUI。 In GooglePlay i found an 3rd Party FtpServer App which can be started and stopped via Intent
在GooglePlay中,我找到了可以通过Intent启动和停止的第三方FtpServer应用程序
Intents:
com.theolivetree.ftpserver.StartFtpServer
com.theolivetree.ftpserver.StopFtpServer
So i would like to use those codes in my app to execute those commands but i dont have any clue how to use them. 所以我想在我的应用程序中使用那些代码来执行那些命令,但是我不知道如何使用它们。 So far i am trying to use Toast to look if anything happen before i move further, but unfortunally nothig happens.
到目前为止,我试图使用Toast来查看是否有任何事情发生,然后再继续前进,但不幸的是,nothig发生了。
my AndroidManifest.XML looks like this: 我的AndroidManifest.XML看起来像这样:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.power.ftpserver"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:allowBackup="true">
<receiver android:enabled="true" android:name="FtpReceiver">
<intent-filter>
<action android:name="android.intent.action.ACTION_POWER_CONNECTED"> </action>
<action android:name="android.intent.action.ACTION_POWER_DISCONNECTED"></action>
</intent-filter>
</receiver>
</application>
</manifest>
FtpReceiver.java FtpReceiver.java
package de.power.ftpserver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;
public class FtpReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context , Intent intent)
{
String action = intent.getAction();
if(action.equals(Intent.ACTION_POWER_CONNECTED))
{
Toast.makeText(context, "FtpServer gestartet", Toast.LENGTH_LONG).show();
}
else if(action.equals(Intent.ACTION_POWER_DISCONNECTED))
{
Toast.makeText(context, "FtpServer beendet", Toast.LENGTH_LONG).show();
}
}
}
When i install the App to my Phone the Console says 当我将应用程序安装到手机上时,控制台会说
[2013-08-02 12:28:19 - FtpServer] No Launcher activity found!
[2013-08-02 12:28:19 - FtpServer] The launch will only sync the application package on the device!
but installs anyway. 但仍然安装。 I can Plug in and Out the Powerconnectioncable but i dont get any Toast Messages.
我可以插入和拔出Powerconnectioncable,但没有收到任何Toast消息。 Can anyone help plz?
有人可以帮忙吗?
I know this is a bit old. 我知道这有点老了。 But just for future reference and as a partial solution, I had the same problem of how to use the Intents provided by the FTP Server app, this is what you're looking for:
但是,作为将来的参考和部分解决方案,我在使用FTP Server应用程序提供的Intent时遇到了相同的问题,这就是您要查找的内容:
Intent startIntent = new Intent("com.theolivetree.ftpserver.StartFtpServer");
sendBroadcast(startIntent); // start
And to stop, it's the same 而且要停止,这是相同的
Intent startIntent = new Intent("com.theolivetree.ftpserver.StopFtpServer");
sendBroadcast(startIntent); // stop
Hope it still can help someone. 希望它仍然可以帮助某人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.