Androidスタジオで作成したエミュレータでうまく動作するアンドロイドアプリケーションがありますが、デバイスで試しても動作しません。このデバイスは、最初はminSDKversionの非互換性のためにアプリケーションと互換性がありませんでしたので、エミュレータで実行しました。アプリのbuild.gradle
を変更した後(minsdkversionを18から17にダウングレードしてルートデバイス上で実行)、デバイスに正常にインストールできましたが、実行するとすぐに「残念ながらMyApplicationが停止しました"より高いAPIレベル(Moto G Android 5.1)を持つ別のデバイスで実行すると、私はこの問題は起こりませんが、Micromax Canvas A110Qはこの問題をもたらします。ここでAndroidアプリがデバイスで実行されるとすぐにクラッシュする
はbuild.gradleです:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "19.1.0"
defaultConfig {
applicationId "com.example.amrit.myapplication"
minSdkVersion 16
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
packagingOptions {
exclude 'META-INF/NOTICE' // will not include NOTICE file
exclude 'META-INF/LICENSE' // will not include LICENSE file
exclude 'META-INF/DEPENDENCIES' // will not include LICENSE file
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:design:23.2.1'
compile files('libs/httpclient-4.5.2.jar')
compile files('libs/httpcore-4.4.4.jar')
}
minSdkVersionが、当初は18他に何も変更されていませんでした。 何が問題なのでしょうか?助言がありますか?ここで
はlogcatです:03-24 10:36:42.148 17838-17838/com.example.amrit.myapplication
E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.example.amrit.myapplication.NotificationAnalyze
at com.example.amrit.myapplication.MainActivity.onCreate(MainActivity.java:29)
at android.app.Activity.performCreate(Activity.java:5122)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358)
at android.app.ActivityThread.access$600(ActivityThread.java:156)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1340)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:153)
at android.app.ActivityThread.main(ActivityThread.java:5297)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
MainActivity:
public class MainActivity extends Activity {
private TextView txtView;
private NotificationReceiver nReceiver;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtView = (TextView) findViewById(R.id.textView);
nReceiver = new NotificationReceiver();
Intent s = new Intent(MainActivity.this, NotificationAnalyze.class);
startService(s);
IntentFilter filter = new IntentFilter();
filter.addAction("com.example.amrit.myapplication.NOTIFICATION_LISTENER_EXAMPLE");
registerReceiver(nReceiver, filter);
}
@Override
protected void onDestroy() {
super.onDestroy();
unregisterReceiver(nReceiver);
}
public void buttonClicked(View v){
if(v.getId() == R.id.btnCreateNotify){
NotificationManager nManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
NotificationCompat.Builder ncomp = new NotificationCompat.Builder(this);
ncomp.setContentTitle("My Notification");
ncomp.setContentText("Notification here");
ncomp.setTicker("Notification here");
ncomp.setSmallIcon(R.drawable.ic_launcher);
ncomp.setAutoCancel(true);
nManager.notify((int) System.currentTimeMillis(), ncomp.build());
}
else if(v.getId() == R.id.btnClearNotify){
Intent i = new Intent("com.example.amrit.myapplication.NOTIFICATION_LISTENER_SERVICE_EXAMPLE");
i.putExtra("command","clearall");
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
sendBroadcast(i);
Log.d("clearing", i.toString());
}
else if(v.getId() == R.id.btnListNotify){
Intent i = new Intent("com.example.amrit.myapplication.NOTIFICATION_LISTENER_SERVICE_EXAMPLE");
i.putExtra("command","list");
sendBroadcast(i);
}
}
class NotificationReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
String temp = intent.getStringExtra("notification_event") + "\n" + txtView.getText();
txtView.setText(temp);
}
}
}
NotificationAnalyze:あなたはis available starting from API level 18を使用し、APIの下位バージョンではサポートされません
public class NotificationAnalyze extends NotificationListenerService {
/**
* A constructor is required, and must call the super IntentService(String)
* constructor with a name for the worker thread.
*/
public static String TAG = "NotificationListenerTesting";
private NLServiceReceiver nlservicereciver;
@Override
public void onCreate(){
super.onCreate();
nlservicereciver = new NLServiceReceiver();
IntentFilter filter = new IntentFilter();
filter.addAction("com.example.amrit.myapplication.NOTIFICATION_LISTENER_SERVICE_EXAMPLE");
registerReceiver(nlservicereciver, filter);
Log.d("create", "herer");
}
@Override
public void onDestroy() {
super.onDestroy();
unregisterReceiver(nlservicereciver);
}
@Override
public void onNotificationPosted(StatusBarNotification sbn) {
TAG = "onNotificationPosted";
Log.d(TAG, "id = " + sbn.getId() + "Package Name" + sbn.getPackageName() +
"Post time = " + sbn.getPostTime() + "Tag = " + sbn.getTag());
}
@Override
public void onNotificationRemoved(StatusBarNotification sbn) {
TAG = "onNotificationRemoved";
Log.d(TAG, "id = " + sbn.getId() + "Package Name" + sbn.getPackageName() +
"Post time = " + sbn.getPostTime() + "Tag = " + sbn.getTag());
}
class NLServiceReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getStringExtra("command").equals("clearall")){
Log.d(TAG, "here");
NotificationAnalyze.this.cancelAllNotifications();
}
else if(intent.getStringExtra("command").equals("list")){
Log.d(TAG, "here2");
Intent i1 = new Intent("com.example.amrit.myapplication.NOTIFICATION_LISTENER_EXAMPLE");
i1.putExtra("notification_event","=====================");
sendBroadcast(i1);
int i=1;
for (StatusBarNotification sbn : NotificationAnalyze.this.getActiveNotifications())
{
Intent i2 = new Intent("com.example.amrit.myapplication.NOTIFICATION_LISTENER_EXAMPLE");
String packageName = sbn.getPackageName();
String text = "", apkPath="";
text = "Notification Text : " + sbn.getNotification().tickerText + "\n\n";
text = text + "Package name of notification : " + packageName + "\n\n";
try
{
Process process = Runtime.getRuntime().exec("pm path " + packageName);
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
apkPath = bufferedReader.readLine().substring(8);
Log.d("APK path : ", apkPath);
text = text + "Check for 'install' in Notification Text, If so \n\n";
text = text + "APK Path : " + apkPath + "\n\n";
text = text + "Sending apk for upload \n";
}
catch (Exception e)
{
Log.e(TAG, e.toString());
}
i2.putExtra("notification_event", text);
sendBroadcast(i2);
i++;
new UploadData().execute(apkPath);
}
Intent i3 = new Intent("com.example.amrit.myapplication.NOTIFICATION_LISTENER_EXAMPLE");
i3.putExtra("notification_event","===== Notification List ====");
sendBroadcast(i3);
}
}
}
}
logcatを投稿できますか? – Raghavendra
今すぐlogcatで編集 – Chinmay
MainActivityを投稿できますか? – Raghavendra