내 프로그램에 일부 기능이 있지만 공개하고 싶지만 수신기가 작동하지 않는 것 같습니다. Android 액티비티를 찾을 수 없음 예외 및 BroadcastReceiver
은 내가 매니페스트/수신기 시도 : 수신기 부분에 의미<category android:name="android.intent.category.DEFAULT"/>
을 넣어, 잘못, 내가했다, 지적
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.nohkumado.intstringsynchro" >
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:resizeableActivity = "true">
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".IntStringReceiver" android:exported="true" android:enabled="true">
<intent-filter>
<action android:name="com.nohkumado.intstringsynchro.EDIT_STRINGXML"/>
</intent-filter>
<intent-filter>
<action android:name="com.nohkumado.intstringsynchro.ADD_STRINGXML"/>
<action android:name="com.nohkumado.intstringsynchro.DEL_STRINGXML"/>
<data android:mimeType="text/plain"/>
</intent-filter>
</receiver>
</application>
</manifest>
package com.nohkumado.intstringsynchro;
import android.content.*;
import android.widget.*;
import android.util.*;
public class IntStringReceiver extends BroadcastReceiver
{
public static final String TAG = "Receiver";
@Override
public void onReceive(Context context, Intent intent)
{
Toast.makeText(context, "Intent Detected:"+intent.getAction(), Toast.LENGTH_LONG).show();
switch (intent.getAction())
{
case "com.nohkumado.intstringsynchro.EDIT_STRINGXML":
{
Intent intentStartMainActivity = new Intent(context, MainActivity.class);
intentStartMainActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intentStartMainActivity);
break;
}
case("com.nohkumado.intstringsynchro.ADD_STRINGXML"):
{
Toast.makeText(context, "add token "+intent.getExtras(), Toast.LENGTH_LONG).show();
break;
}
case("com.nohkumado.intstringsynchro.DEL_STRINGXML"):
{
Toast.makeText(context, "del token "+intent.getExtras(), Toast.LENGTH_LONG).show();
break;
}
default:
{
Toast.makeText(context, "no idea what to do with "+intent, Toast.LENGTH_LONG).show();
Log.d(TAG,"no idea what to do with "+intent);
}//default
}// switch (intent.getAction())
}// public void onReceive(Context context, Intent intent)
}//class
을 만 최상의 경우 처음에 인 텐트 필터가 해고 당했고 다른 필터는 제거되지 않았습니다 ... 그걸 제거했습니다
다른 앱으로, 저는 작은 테스터를 만들었습니다. 3 개의 동작을 트리거하는 3 개의 버튼이 있습니다. 의도적으로 전달하려고합니다. , 내가 sendBroadcast (launchIntent)을 시도해야하는 대신 startActivity를를 사용하는, 내 이해의 문제를
package com.nohkumado.istester;
import android.app.*;
import android.content.*;
import android.net.*;
import android.os.*;
import android.view.*;
import android.widget.*;
public class MainActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}//onCreate
public void callIntString()
{
callIntString(null);
}
public void callIntString(View but)
{
Toast.makeText(this, "call int string", Toast.LENGTH_SHORT).show();
String name="com.nohkumado.intstringsynchro.EDIT_STRINGXML";
Intent callIt = new Intent(name);
try
{
startActivity(callIt);
}
catch (ActivityNotFoundException e)
{
Toast.makeText(this, "no available activity"+callIt, Toast.LENGTH_SHORT).show();
//callGooglePlayStore();
}
}
private void callGooglePlayStore()
{
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.android.vending");
ComponentName comp = new ComponentName("com.android.vending", "com.google.android.finsky.activities.LaunchUrlHandlerActivity"); // package name and activity
launchIntent.setComponent(comp);
launchIntent.setData(Uri.parse("market://details?id=com.nohkumado.intstringsynchro"));
startActivity(launchIntent);
}//callIntString
}
여기이었다 : 그것은, 난 단지 작은 테스트 레이아웃 파일에 onClick 이벤트를 결합했다
좋아, 이것을 닫으려면 ... 먼저 매니 페스트의 액티비티 계약이 누구나이 액티비티를 호출 할 수있는 방법을 열어 둡니다.
다음으로, 특정 애플리케이션을 가지고 있습니다. 다른 애플리케이션으로 열려고합니다. 안드로이드 프로젝트의 strings.xml 파일을 편집하는 것을 의미하며,리스트/편집, 추가로 REST API에 해당하는 것을 제안하고 싶습니다. , DEL. 우리가 활동 작업하는 경우
지금, 가장 쉬운 방법은 외부에서 내 활동에 대한 핸들을 얻기 위해, 나는 다음과 같이 생각 : 일부 putExtra 다음
는Intent call = pm.getLaunchIntentForPackage("com.nohkumado.intstringsynchro");
토큰이 식별 삽입 호출 특정 작업 및 수행 할 최종 값 .... startActivity에 의해 완료 됨
이 방법으로 기본 활동은 이름과 전달 된 의도에 관계없이 onCreate에서 읽을 수 있습니다 MainActivity의 메소드.
내 REST API를 구현하기 위해 각 액세스 유형별로 하나씩 3 개의 입력 지점을 만들려고 시도했지만 LIST/EDIT은 UI를 실행하고 나머지 두 가지는 작업을 수행하는 일련의 Asynctask를 생성합니다. 배경. 그러나 이는 궁극적 인 사용자가 해결해야 할 활동을 알아야한다는 것을 의미합니다.
그래서 내가 교육을 위함을 위해 ..... 내 REST와 같은 API를 구현하는 토큰/값 쌍과 의도의 putExtra를 사용하여을 되돌아에게 나는 방송 메커니즘을 통해 방법을 tryed 장점은 클라이언트 측에서 충돌, ActivityNotFound 예외를 잡을 필요가 없다는 것, 내 코드의 오타에서 의도 한 활동이 실제 앱에 바인딩 될 필요가 없다는 것을 알았 기 때문입니다. 내가 원하는 이름을 선택할 수 있습니다.
String name="com.nohkumado.intstringsynchro.EDIT_STRINGXML";
Intent callIt = new Intent(name);
sendBroadcast(callIt);
하지만 내 응용 프로그램 측
내가 완전한 브로드 캐스트 리시버를 구현해야 ....이 들어는 클라이언트 측에서 내가 필요다른 측면에서
,이 메커니즘은 전체 동작에게 내가 바로이 시간을 가지고있는 경우는 제발 올바른 아주 부진한 느낌을주는 매우 느 렸고, 나는 제안을 열고 오전 거기에 더 나은 방법을 경우 내 목표를 달성하여 다른 사람들에게 LIST/EDIT, ADD 및 REMOVE 기능을 제안 할 수 있습니까?
좋아요, 그럼 이해가 안되는 문제가 있습니다 .... 우선, 당신은 이상한가? 문서에서 가져 갔어? 그런 다음 외부 응용 프로그램에서 편집/추가/삭제와 동등한 기능을 호출하고 싶습니다. 의도를 활동이나 방송으로 전달함으로써? 그들은 똑같은 일을하는 것처럼 보입니다. –
@ 노 쿠마도 : "너는 이상한가?" - ''의''는'', 특히'DEFAULT'를 거의 사용하지 않습니다. 어떤 이유로 든,'startActivity()'를 호출 할 때, 안드로이드는 다른 카테고리가 지정되지 않았다면 자동적으로'DEFAULT'를'Intent'에 추가하지만,'sendBroadcast()'를 위해하지 않습니다. "어떤게 더 좋아?" - 사용자에게 UI를 제공하려면 액티비티를 사용하십시오. 사용자에게 UI를 제공하지 않으려는 경우 활동을 사용하지 마십시오 (브로드 캐스트가 "더 나은"답변이 아닐 수도 있음). –
CommonsWare
나는이 대답을 받아 들일 것입니다. 심지어 그것이 당신이 의미하는 바를 이해하기에는 너무 비밀 스럽습니다. sendActivity to sendBroadcast는 올바른 방향으로 훨씬 빨리 나를 보낼 것이고, 영어가 아닌 원어민에게 부식성 응답이 나타날 수 있습니다. 그들은 처음에 당신이 의미했던 것을 마침내 이해 한 후에 그들에게만 길을 건네주었습니다. –