0

MainActivityからfabボタンを使ってアクティビティを開始しようとしています。私のコードは以下の通りです。私が手に例外がある:Android startActivity例外

ActivityNotFoundException: Unable to find explicit activity class //packagename; have you declared this activity in your AndroidManifest.xml? 

例外が私のアンドロイドマニフェストに私を指しているが、私はおそらくない正確ものの、そこに活動を追加しました。あなたがうまくいけば、私は「見ることができるようにAndroidManifest.xmlを

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

<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" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme.NoActionBar"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
    <Activity android:name=".Listen" 
     android:label="@string/app_name"> 
     <intent-filter> 
      <action android:name="android.intent.action.DEFAULT" /> 
      <category android:name="accesscontrol2016.Listen" /> 
     </intent-filter> 
    </Activity> 
</application> 

import android.app.Activity; 
import android.app.Notification; 
import android.app.NotificationManager; 
import android.app.PendingIntent; 
import android.content.Context; 
import android.content.Intent; 
import android.os.Bundle; 

import com.estimote.sdk.Beacon; 
import com.estimote.sdk.BeaconManager; 
import com.estimote.sdk.Region; 
import com.estimote.sdk.SystemRequirementsChecker; 

import java.util.List; 
import java.util.UUID; 

public class Listen extends Activity { 

    private BeaconManager beaconManager; 
    private Region region; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     beaconManager = new BeaconManager(this); 

     region = new Region("ranged region", 
       UUID.fromString("B9407F30-F5F8-466E-AFF9-25556B57FE6D"), null, null); 
    } 


    @Override 
    protected void onResume() { 
     super.onResume(); 

     SystemRequirementsChecker.checkWithDefaultDialogs(this); 

     beaconManager.setMonitoringListener(new BeaconManager.MonitoringListener() { 
      @Override 
      public void onEnteredRegion(Region region, List<Beacon> list) { 
       showNotification(
         "Welcome..", 
         "to the AccessLab!"); 
      } 
      @Override 
      public void onExitedRegion(Region region) { 
       showNotification(
         "You've left the lab..", 
         "Goodbye!"); 
      } 
     }); 


     beaconManager.connect(new BeaconManager.ServiceReadyCallback() { 
      @Override 
      public void onServiceReady() { 
       beaconManager.startMonitoring(region); 
      } 
     }); 
    } 



    public void showNotification(String title, String message) { 
     Intent notifyIntent = new Intent(this, MainActivity.class); 
     notifyIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); 
     PendingIntent pendingIntent = PendingIntent.getActivities(this, 0, 
       new Intent[] { notifyIntent }, PendingIntent.FLAG_UPDATE_CURRENT); 
     Notification notification = new Notification.Builder(this) 
       .setSmallIcon(android.R.drawable.ic_dialog_info) 
       .setContentTitle(title) 
       .setContentText(message) 
       .setAutoCancel(true) 
       .setContentIntent(pendingIntent) 
       .build(); 
     notification.defaults |= Notification.DEFAULT_SOUND; 
     NotificationManager notificationManager = 
       (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
     notificationManager.notify(1, notification); 
    } 

} 

import android.content.Intent; 
import android.os.Bundle; 
import android.support.design.widget.FloatingActionButton; 
import android.support.design.widget.Snackbar; 
import android.support.v7.app.AppCompatActivity; 
import android.support.v7.widget.Toolbar; 
import android.view.View; 
import android.view.Menu; 
import android.view.MenuItem; 

public class MainActivity extends AppCompatActivity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
    setSupportActionBar(toolbar); 

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); 

    /* 
    * OnLongClick - start listening via Listen class 
    * */ 
    fab.setOnLongClickListener(new View.OnLongClickListener() { 
     @Override 
     public boolean onLongClick(View view) { 

      Intent intent = new Intent(getApplicationContext(), Listen.class); 

      Snackbar.make(view, "Bluetooth authentication is on", Snackbar.LENGTH_LONG) 
        .setAction("Action", null).show(); 
      startActivity(intent); 
      return true; 
     } 
    }); 

    fab.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      Snackbar.make(view, "Bluetooth authentication turned off", Snackbar.LENGTH_LONG) 
        .setAction("Action", null).show(); 
     } 
    }); 

} 

Listen.java

MainActivity.java:ここに私のコードですveは012を追加しましたAndroid Manifestでの私のアクティビティへのクラス。私は意図が正しく設定されているかどうかわからない、getApplicationContext()。どんな助けでも大歓迎です。

+0

チェックフルパスクラスのサンプル:<活動のアンドロイド:名=「accesscontrol.accesscontrol」 –

+0

私のマニフェストファイルは、私が投稿コードである@SaravInfern – Zoe

+0

シェアあなたマニフェストファイル – SaravInfern

答えて

1

解決するのは簡単です:

ActivityNotFoundException:...あなたはあなたのAndroidManifest.xmlでこの活動を宣言していますか?

よろしいですか?

単にあなたのマニフェストにこれを追加します。

<activity android:name=".Activity"></activity> 

それとも、あなたはすべての活動の活動

<activity 
     android:name=".Activity" 
     android:label="@string/app_name" 
     > 
     <intent-filter> 
      <action android:name="android.intent.action.DEFAULT" /> 

      <category android:name="com.your.package.CLASS" /> 
     </intent-filter> 
    </activity> 

のためのより多くのプロパティを設定する必要がある場合は、正しく動作するために宣言する必要があります。上記は、ニーズに合わせて編集しやすい汎用的な例です。注意:アクティビティタグを大文字にすることはできません

マニフェスト

EDITにそのようにすべての活動を宣言

<activity android:name=".Listen" 
    android:label="@string/app_name"> 
    <intent-filter> 
     <action android:name="android.intent.action.DEFAULT" /> 
     <category android:name="accesscontrol2016.Listen" /> 
    </intent-filter> 
</activity> 
+0

私の編集した質問のAndroidManifestファイルをご覧ください。私はあなたが提案したことを行ったが、私はまだActivityNotFoundExceptionを取得しています。 –

+0

アクティビティを開始するのにインテントフィルタは必要ありません –

+0

@JohnSetterパッケージ名とクラスを含むように例外を検出できませんか? – Zoe

0

をあなたが投稿マニフェストでは、あなたはこれを持っている:

<Activity android:name=".Listen" 
    android:label="@string/app_name"> 
    <intent-filter> 
     <action android:name="android.intent.action.DEFAULT" /> 
     <category android:name="accesscontrol2016.Listen" /> 
    </intent-filter> 
</Activity> 

まず、は必要ありません0 Listen<activity>宣言内の宣言。そして、<activity>宣言でlowercae "a"を使用する必要があります。あなたは大文字の "A"を使用しました。タグ ''は認識されません(あなたのIDEはあなたにそれを伝えるべきです)。