简体   繁体   中英

Start FtpServer when charging the Phone

i want to make an App which starts an FTPServer when my Phone is conncted to Power. I dont want my App to have an GUI. In GooglePlay i found an 3rd Party FtpServer App which can be started and stopped via Intent

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.

my AndroidManifest.XML looks like this:

<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

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. 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:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM