用动作制作意图的问题[服务器用于php - android app]

时间:2016-06-16 22:49:50

标签: java android android-intent

我正在使用App Server For PHP for android。

在上一次更新中,应用程序允许对Stop,start和其他人进行意图。 Here the class

当我尝试按意图访问时,返回错误“找不到处理意图的活动{act = STOP}”

班级内的指令是:

/**
 * External intent action information class
 *
 * Here you will find:
 * ACTION_* - supported intent actions
 * ERROR_* - error codes with description
 * FIELD_* - intent data fields
 *
 * Intent sending works this way:
 * #1 you send intent with supported action and server package name
 * #2 user sees dialog asking if he allows your application to execute action for your application
 * #3 if user allows action, then action progress dialog will be shown
 * #4 you get call to your onActivityResult, with resultCode and sometimes data intent. resultCode
 * will be Activity.RESULT_OK or error code
 *
 * @see IntentActionRequest - it is helper class for sending external intents
 */

MainActivity.java 中的代码是:

package com.itdep.lact.restartserverphp;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    Button btn;
    Context c = this;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btn=(Button)findViewById(R.id.btn1);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent server = new Intent("com.esminis.server.php");
                if (server.resolveActivity(getPackageManager()) != null ){
                    //Toast.makeText(c.getApplicationContext(), server.resolveActivity(getPackageManager()).toString(), Toast.LENGTH_LONG).show();
                    startActivityForResult(server, 0);
                }
                try {
                    server.setAction("STOP");
                    c.startActivity(server);
                    Toast.makeText(c.getApplicationContext(), "Good", Toast.LENGTH_LONG).show();
                } catch (Exception e) {
                    Log.e("error", e.getMessage());
                    Toast.makeText(c.getApplicationContext(), "error: " + e.getMessage(), Toast.LENGTH_LONG).show();
                }
            }
        });



    }
}

我的清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.itdep.lact.restartserverphp">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="com.esminis.server.php"/>
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>

</manifest>
最好的问候。

0 个答案:

没有答案