0
我正在爲一個應用程序(只是一個有趣的項目爲我自己,我沒有把它放在Play商店),將發送一個敬酒。我的最終目標是有一個shell命令發送一個敬酒。我不在乎我如何得到這些結果,我只是想讓它工作。自定義意圖崩潰我的應用程序
我在想我會有shell命令發送一個意圖到我的應用程序。我使用的是自定義的意圖:
<intent-filter>
<action android:name="com.tylerr147.toast" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
當我使用adb shell am start -a "com.tylerr147.toast" --es "android.intent.extra.TEXT" "toasty" -t "text/plain"
啓動它,我的應用程序崩潰。
這裏是我的AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.tylerr147.intenttoast" >
<application android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity android:name=".handler" >
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="com.tylerr147.toast" />
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
</application>
</manifest>
而且我handler.java
package com.tylerr147.intenttoast;
import android.app.*;
import android.content.*;
import android.net.*;
import android.os.*;
import android.widget.*;
import java.util.*;
import android.util.*;
public class handler extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState) {
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
handleSendText(intent);
}
public void handleSendText(Intent intent)
{
try{ String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
if (sharedText != null) {
// Update UI to reflect text being shared
Toast.makeText(getApplicationContext(), sharedText, Toast.LENGTH_LONG).show();
}
} catch(Exception e) {
Log.e("Boked", e.toString());
}
}
}
感謝您的幫助!
雖然這次沒有崩潰,但它也沒有做吐司。 –