我收到以下错误:
android.content.ActivityNotFoundException: Unable to find explicit activity class {ie.ittralee.finalyeartest.finalyeartest/ie.ittralee.finalyeartest.finalyeartest.WiFiDirectActivity}; have you declared this activity in your AndroidManifest.xml?
现在我相信"WifiDirectActivity"应该在路径中的第一个'最后一年测试'之后。 不知道为什么有两个?
WifiDirectActivity.java
import ie.ittralee.finalyeartest.finalyeartest.DeviceListFragment.DeviceActionListener;
import static ie.ittralee.finalyeartest.finalyeartest.R.id.frag_list;
public class WiFiDirectActivity extends Activity implements ChannelListener, DeviceActionListener {
public static final String TAG = "LightShare";
private WifiP2pManager manager;
private boolean isWifiP2pEnabled = false;
private boolean retryChannel = false;
private final IntentFilter intentFilter = new IntentFilter();
private Channel channel;
private BroadcastReceiver receiver = null;
/**
* @param isWifiP2pEnabled the isWifiP2pEnabled to set
*/
public void setIsWifiP2pEnabled(boolean isWifiP2pEnabled) {
this.isWifiP2pEnabled = isWifiP2pEnabled;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
...More code
如果您需要任何额外的代码,请告诉我。 上面的类下面只是一些 Wifi 连接的东西,不相关。 希望不是...
清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ie.ittralee.finalyeartest.finalyeartest">
<uses-sdk android:minSdkVersion="14" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Google Play filtering -->
<uses-feature android:name="android.hardware.wifi.direct" android:required="true"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="Light Share"
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>
</activity>
<activity android:name=".ShareFilesActivity"></activity>
<!-- Used for transferring files after a successful connection -->
<service android:enabled="true" android:name=".FileTransferService" />
</application>
</manifest>
将您的活动添加到清单中,如下所示:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="Light Share"
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>
</activity>
<activity android:name=".ShareFilesActivity"></activity>
<activity android:name=".WiFiDirectActivity">
<!-- Used for transferring files after a successful connection -->
<service android:enabled="true" android:name=".FileTransferService" />
</application>
修复只是在我的清单中添加活动。 不知何故完全绕过了这一点。
<activity android:name=".WiFiDirectActivity"></activity>
您是否在 AndroidManifest 中声明了您的活动.xml?如下所示:
<activity android:name=".WiFiDirectActivity"
android:theme="@style/AppTheme.NoActionBar">
</activity>