I am trying to send a simple message from my wear [Emulator] to my android phone, The message should have been sent according to my logs on the wear but it does not trigger my "showToast" method on my phone [it should be triggered when a message is received]. Anyone has an idea what I could be doing wrong?
This is my Wear Manifest
<manifest package="georgikoemdzhiev.weartesttwo"
xmlns:android="http://schemas.android.com/apk/res/android">
<uses-feature android:name="android.hardware.type.watch"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#android:style/Theme.DeviceDefault">
<uses-library
android:name="com.google.android.wearable"
android:required="false"/>
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.DeviceDefault.Light">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
This is my Mobile manifest
<manifest package="georgikoemdzhiev.weartesttwo"
xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<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>
<service android:name=".ReceiveMessageService">
<intent-filter>
<action android:name="com.google.android.gms.wearable.MESSAGE_RECEIVED" />
<data android:scheme="wear" android:host="*" android:pathPrefix="/prefix" />
</intent-filter>
</service>
</application>
This is my Wear logic [I have a button that sends the showToast message]
public class MainActivity extends WearableActivity {
private static final long CONNECTION_TIME_OUT_MS = 2500;
private static final String TAG = MainActivity.class.getSimpleName();
private CircularButton mSendButton;
private List<Node> myNodes = new ArrayList<>();
private static final SimpleDateFormat AMBIENT_DATE_FORMAT =
new SimpleDateFormat("HH:mm", Locale.UK);
private BoxInsetLayout mContainerView;
private TextView mTextView;
private TextView mClockView;
private GoogleApiClient mClient;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setAmbientEnabled();
mSendButton = (CircularButton)findViewById(R.id.sendToast);
mSendButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
sendToastMessage();
}
});
mClient = new GoogleApiClient.Builder(this)
.addApiIfAvailable(Wearable.API)
.build();
getNodes();
mContainerView = (BoxInsetLayout) findViewById(R.id.container);
mTextView = (TextView) findViewById(R.id.text);
mClockView = (TextView) findViewById(R.id.clock);
}
private void sendToastMessage() {
Log.d(TAG,"Sending message... Nodes List size:" + myNodes.size());
// send toast message logic...
new Thread(new Runnable() {
#Override
public void run() {
for(Node n:myNodes) {
Log.d(TAG,"Sending message to node:"+n.getDisplayName());
Wearable.MessageApi.sendMessage(mClient,n.getId(),"/showToast",null);
}
}
});
}
private List<Node> getNodes(){
new Thread(new Runnable() {
//
#Override
public void run() {
Log.d(TAG,"Getting nodes...");
mClient.blockingConnect(CONNECTION_TIME_OUT_MS, TimeUnit.MILLISECONDS);
NodeApi.GetConnectedNodesResult result = Wearable.NodeApi.getConnectedNodes(mClient).await();
List<Node> nodes = result.getNodes();
for(Node n:nodes){
Log.d(TAG,"Adding Node: "+n.getDisplayName());
myNodes.add(n);
}
Log.d(TAG,"Getting nodes DONE!");
}
}).start();
return null;
}
}
This is my ReceiveMessageService in Mobile
public class ReceiveMessageService extends WearableListenerService {
#Override
public void onMessageReceived(MessageEvent messageEvent) {
Log.d("ReceiveMessageService","onMessageReceived");
//if(messageEvent.getPath().equals("/showToast")) {
showToast(messageEvent.getPath());
//}
}
private void showToast(String message) {
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
}
}
This is my MainActivity in Mobile
public class MainActivity extends AppCompatActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener{
private static final String TAG = MainActivity.class.getSimpleName();
private GoogleApiClient mGoogleApiClient;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Wearable.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
mGoogleApiClient.connect();
}
#Override
public void onConnected(#Nullable Bundle bundle) {
Log.d(TAG,"onConnected");
}
#Override
public void onConnectionSuspended(int i) {
Log.d(TAG,"onConnectionSuspended");
}
#Override
public void onConnectionFailed(#NonNull ConnectionResult connectionResult) {
Log.d(TAG,"onConnectionFailed");
}
It looks like you are using wrong pathPrefix in your mobile side AndroidManifest. Try to replace
<data android:scheme="wear" android:host="*" android:pathPrefix="/prefix" />
with
<data android:scheme="wear" android:host="*" android:pathPrefix="/showToast" />
Edit
Also keep in mind that MessageApi is not guarantee to deliver a message even if it returns a successful result code as Google's document stated:
Note: A successful result code does not guarantee delivery of the message. If your app requires data reliability, use DataItem objects or the ChannelApi class to send data between devices.
Related
I am trying to implement simple quick settings tile with the help of google docs,
but my tile appears to be there but greyed out(intent activity)- I can't click or do anything with it and cant remove it either without restarting my phone(one plus 3T/oreo8.0.0).
and the same thing goes with sample code google provided.
what things do i need to keep in mind/ how to do it?
is there anything I am missing?
I saw one similar question but it was a bit over my head.
MANIFEST
<application
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
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>
<service
android:name=".QSIntentService"
android:icon="#drawable/ic_android_black_24dp"
android:label="#string/qs_intent_tile_label"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE" />
</intent-filter>
</service>
<activity
android:name=".ResultActivity"
android:label="#string/result_label"/>
</application>
JAVA (Main ACtivity)
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
QSintentservice.java
public class QSIntentService extends TileService{
private static final String SERVICE_STATUS_FLAG = "serviceStatus";
private static final String PREFERENCES_KEY = "com.google.android_quick_settings";
#Override
public void onClick() {
updateTile();
boolean isCurrentlyLocked = this.isLocked();
if (!isCurrentlyLocked) {
Resources resources = getApplication().getResources();
Tile tile = getQsTile();
String tileLabel = tile.getLabel().toString();
String tileState = (tile.getState() == Tile.STATE_ACTIVE) ?
resources.getString(R.string.service_active) :
resources.getString(R.string.service_inactive);
Intent intent = new Intent(getApplicationContext(),
ResultActivity.class);
intent.putExtra(ResultActivity.RESULT_ACTIVITY_NAME_KEY,
tileLabel);
intent.putExtra(ResultActivity.RESULT_ACTIVITY_INFO_KEY,
tileState);
startActivityAndCollapse(intent);
}
}
private void updateTile() {
Tile tile = this.getQsTile();
boolean isActive = getServiceStatus();
Icon newIcon;
String newLabel;
int newState;
if (isActive) {
newLabel = String.format(Locale.US,
"%s %s",
getString(R.string.tile_label),
getString(R.string.service_active));
newIcon = Icon.createWithResource(getApplicationContext(), ic_android_black_24dp);
newState = Tile.STATE_ACTIVE;
} else {
newLabel = String.format(Locale.US,
"%s %s",
getString(R.string.tile_label),
getString(R.string.service_inactive));
newIcon =
Icon.createWithResource(getApplicationContext(),
android.R.drawable.ic_dialog_alert);
newState = Tile.STATE_INACTIVE;
}
tile.setLabel(newLabel);
tile.setIcon(newIcon);
tile.setState(newState);
tile.updateTile();
}
private boolean getServiceStatus() {
SharedPreferences prefs =
getApplicationContext()
.getSharedPreferences(PREFERENCES_KEY,
MODE_PRIVATE);
boolean isActive = prefs.getBoolean(SERVICE_STATUS_FLAG, false);
isActive = !isActive;
prefs.edit().putBoolean(SERVICE_STATUS_FLAG, isActive).apply();
return isActive;
}
}
Result.java
public class ResultActivity extends AppCompatActivity {
public static final String RESULT_ACTIVITY_INFO_KEY = "resultActivityInfo";
public static final String RESULT_ACTIVITY_NAME_KEY = "resultActivityName";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_result);
if (getIntent() != null) {
Bundle extras = getIntent().getExtras();
assert extras != null;
String tileState = extras.getString(RESULT_ACTIVITY_INFO_KEY);
String tileName = extras.getString(RESULT_ACTIVITY_NAME_KEY);
TextView outputText = findViewById(R.id.result_info);
outputText.setText(String.format(Locale.US,
getString(R.string.result_output),
tileName,
tileState));
TextView returnHome = findViewById(R.id.result_return_main);
returnHome.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent goHome = new Intent(getApplicationContext(),
MainActivity.class);
startActivity(goHome);
}
});
}
}
}
This code works fine on other devices. However, there is an issue in one plus quick setting menu as its observed and brought to notice. Check the below link to verify,
https://forums.oneplus.net/threads/android-oreo-8-0-oxigenos-quick-settings-bug.690621/
public void CameraOnClick(){
using (AndroidJavaClass javaClass = new AndroidJavaClass ("com.d3d.viewer.NativePlugin")) {
using (AndroidJavaObject currentActivity = javaClass.CallStatic<AndroidJavaObject> ("instance")) {
Debug.Log ("Start Camera############");
//javaClass.CallStatic ("showCamera");
currentActivity.Call("showCamera");
}
}
}
public void getimageUrl1(string ImageUrl){
imageurl1 = ImageUrl;
Debug.Log ("ImageUrl11111111111111111111"+ImageUrl);
}
Android source
public class NativePlugin extends UnityPlayerActivity {
final Activity b = m_instance;
final Activity a = UnityPlayer.currentActivity;
private static NativePlugin m_instance;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
UnityPlayer.UnitySendMessage("PlusPopupManager","getimageUrl1","22222"); //don't activate
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 1);
}
public static NativePlugin instance()
{
if(m_instance == null)
{
m_instance = new NativePlugin();
}
return m_instance;
}
public void showCamera () // Connect Camera
{
UnityPlayer.UnitySendMessage("PlusPopupManager","getimageUrl1","111111"); //activate
a.runOnUiThread(new Runnable()
{
public void run() {
Intent intent = new Intent(a, NativePlugin.class);
a.startActivity(intent);
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
UnityPlayer.UnitySendMessage("PlusPopupManager","getimageUrl1","333333");//don't activate
}
}
manifast.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.d3d.viewer">
<application android:allowBackup="true" android:label="#string/app_name"
android:supportsRtl="true">
<activity android:name="com.d3d.viewer.NativePlugin" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:label="#string/app_name" android:screenOrientation="landscape" android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen" android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera.autofocus"/>
</manifest>
I make ARR android plugins.and import Unity3d.
'UnityPlayer.UnitySendMessage' is activated when I call 'showCamera'.
but don't activate when I call intent( NativePlugin) funtion.
why don't call 'UnityPlayer.UnitySendMessage' funtion on android activity.
I am doing an application using the PreferenceFragmentCompat when i call the PreferenceFragmentCompat i am getting the error like java.lang.NoClassDefFoundError i am getting the confused what to do i have tried and checked some google suggestion it is not solving the problem please help to solve it
my Class which extends PreferenceFragmentCompat is as i am showing the code below
public class AutoAnswerPreferenceActivity extends PreferenceFragmentCompat implements OnSharedPreferenceChangeListener {
private AutoAnswerNotifier mNotifier;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preference);
mNotifier = new AutoAnswerNotifier(getActivity());
mNotifier.updateNotification();
SharedPreferences sharedPreferences = getPreferenceManager().getSharedPreferences();
sharedPreferences.registerOnSharedPreferenceChangeListener(this);
/*PreferenceManager preferenceManager = getPreferenceManager();
preferenceManager.getSharedPreferences()
.registerOnSharedPreferenceChangeListener(this);*/
}
#Override
public void onDestroy() {
getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
super.onDestroy();
}
#Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (key.equals("enabled")) {
mNotifier.updateNotification();
}
}
#Override
public void onCreatePreferences(Bundle arg0, String arg1) {
// TODO Auto-generated method stub
}
and my fragment class is as shown below
public class AutoAnswarFragment extends Fragment {
#Override
public void onCreate(#Nullable Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
// getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.container, new AutoAnswerPreferenceActivity()).commit();
getActivity().getSupportFragmentManager().beginTransaction()
.replace(R.id.container, new AutoAnswerPreferenceActivity ()).commit();
}
}
In Navigation Drawer i am calling the fragment to replace it as shown below
getSupportFragmentManager().beginTransaction()
.replace(R.id.container, new AutoAnswarFragment(),null).commit();
the manifest file is as shown below
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".NavigationDrawerMainActivity"
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="com.koteswara.wise.autoanswer.AutoAnswerReceiver"
android:enabled="true" >
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
<receiver
android:name="com.koteswara.wise.autoanswer.AutoAnswerBootReceiver"
android:enabled="true" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service android:name="com.koteswara.wise.autoanswer.AutoAnswerIntentService" />
<activity android:name="com.koteswara.wise.settings.GetCallerInfoActivity"
android:theme="#android:style/Theme.Dialog"
></activity>
</application>
please help to solve this i will be great full to you people. I am getting this error from the last one week
I have a wearable app that has a couple of fragments created with FragmentGridPagerAdapter. One of the fragments has a couple of CircularButtons and I want to update the backcolor of the button when a message is received from handheld phone. I have no problems in receiving the message. However, button's color (or anything in UI) doesn't update. Do you know how can I fix this?
public class UIPageAdapter extends FragmentGridPagerAdapter {
private final Context mContext;
MainControlFragment[] mainControlFragments;
private List mRows;
uiChangeListener mUIChangeListener = new uiChangeListener();
public UIPageAdapter(Context ctx, FragmentManager fm) {
super(fm);
Log.i("pageAdapter", "constructor");
mContext = ctx;
mainControlFragments = new MainControlFragment[2];
mainControlFragments[0] = new MainControlFragment();
mainControlFragments[1] = new MainControlFragment();
LocalBroadcastManager.getInstance(ctx).registerReceiver(mUIChangeListener,new IntentFilter(Constants.BROADCAST_CONTROL_HOME));
}
#Override
public Fragment getFragment(int row, int col) {
Log.i("PageAdapter","Fragment #" + col +"is asked");
return mainControlFragments[col];
}
public void changeStatus(int button, boolean status) {
mainControlFragments[0].setStatus(button,status);
// notifyDataSetChanged();
}
public class uiChangeListener extends BroadcastReceiver{
#Override
public void onReceive(Context context, Intent intent) {
String act = intent.getAction();
if (act == Constants.BROADCAST_CONTROL_HOME) {
int key = intent.getIntExtra(Constants.CONTROL_HOME_KEY,-1);
String command = intent.getStringExtra(Constants.CONTROL_HOME_COMMAND);
changeStatus(key,command.equals("on"));
}
}
}
#Override
public int getRowCount() {
return 1;
}
#Override
public int getColumnCount(int i) {
return 2;
}
}
Basically when a message received from the handheld device a WearableListener class broadcasts an update message to the UIPageAdapter
This is the listener class
public class ListenerService extends WearableListenerService
{
String tag = "ListenerService";
#Override
public void onMessageReceived(MessageEvent messageEvent) {
final String message = (new String(messageEvent.getData()));
Log.i(tag,message);
LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(Constants.BROADCAST_CONTROL_HOME)
.putExtra(Constants.CONTROL_HOME_KEY, messageEvent.getPath())
.putExtra(Constants.CONTROL_HOME_COMMAND,Integer.parseInt(message.substring(1)))
.putExtra("caller",tag));
}
#Override
public void onCreate() {
super.onCreate();
Log.i(tag, "onCreate");
}
}
Manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="smartstuff.com.tr.myautomationtool" >
<uses-feature android:name="android.hardware.type.watch" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.DeviceDefault" >
<uses-library
android:name="com.google.android.wearable"
android:required="false" />
<service android:name=".ListenerService">
<intent-filter>
<action android:name="com.google.android.gms.wearable.BIND_LISTENER" />
</intent-filter>
</service>
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.DeviceDefault.Light" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Finally the custom fragment
public class MainControlFragment extends Fragment{
ViewGroup container;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Log.i("controlFragment","create");
this.container = container;
// Inflate the layout for this fragment
return inflater.inflate(R.layout.main_control, container, false);
}
public void setStatus(int button, boolean status) {
Log.i("controlFragment",button + " "+ status);
CircularButton[] btns = new CircularButton[4];
btns[0] = (CircularButton) container.findViewById(R.id.cbtnFront);
btns[1] = (CircularButton) container.findViewById(R.id.cbtnBack);
btns[2] = (CircularButton) container.findViewById(R.id.cbtnBed);
btns[3] = (CircularButton) container.findViewById(R.id.cbtnCoffee);
btns[button].setColor(status?Color.BLACK:Color.RED);
}
}
I also tried the notifyDataSetChanged(); method in UIPageAdapter however it it only calls onCreateView method in fragment. Any help is appreciated
I'm assuming you already resolved this but I had to add a call to invalidate() on the CircularButton after calling setColor():
_circularButton.setColor(ContextCompat.getColor(getActivity(), buttonColor));
_circularButton.invalidate();
Without the call to invalidate the UI only updated some of the time.
I try to create Twitter client and now I deal with authorization via OAuth protocol. I have created "Sign In" button to come in WebView and load twitter authorization URL, that's work. However, when the authorization is accepted successfuly and Twitter service redirect me to my callback I receive error web page in WebView. That is to say I am not redirected to my activity, I still stay in WebView. But if try the same way via browser, it`s working. What the problem is that?
Main Activivty:
public class Twitter extends Activity implements OnClickListener {
Button bSignIn;
TextView status;
private OAuthConsumer consumer;
private OAuthProvider provider;
private String url;
final String TAG = getClass().getName();
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
bSignIn = (Button) findViewById(R.id.bSignIn);
status = (TextView) findViewById(R.id.tvStatus);
bSignIn.setOnClickListener(this);
}
public void onClick(View v) {
new OAuthWebViewProcess().execute();
}
public class OAuthWebViewProcess extends AsyncTask<Void, Void, Void> {
ProgressDialog dialog;
protected void onPreExecute() {
dialog = ProgressDialog.show(Twitter.this, null,
"Connecting, please wait...");
}
protected Void doInBackground(Void... params) {
try {
consumer = new CommonsHttpOAuthConsumer(Constants.CONSUMER_KEY,
Constants.CONSUMER_SECRET);
provider = new CommonsHttpOAuthProvider(Constants.REQUEST_URL,
Constants.ACCESS_URL, Constants.AUTHORIZE_URL);
url = provider.retrieveRequestToken(consumer,
Constants.OAUTH_CALLBACK_URL);
} catch (Exception e) {
Log.e(TAG, "Error during OAUth retrieve request token", e);
}
return null;
}
protected void onPostExecute(Void result) {
//Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
Intent i = new Intent(Twitter.this, TwitterWebView.class);
i.putExtra("url", Uri.parse(url).toString());
startActivityForResult(i, 1);
dialog.dismiss();
}
}
}
WebView for Twitter:
public class TwitterWebView extends Activity {
String url;
WebView TwitterWebView;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.twitterwebview);
Bundle extras = getIntent().getExtras();
url = extras.getString("url");
try {
TwitterWebView = (WebView) findViewById(R.id.wvTwitter);
TwitterWebView.setWebViewClient(new TwitterWebViewClient(){
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
TwitterWebView.getSettings().setJavaScriptEnabled(true);
TwitterWebView.getSettings().setDomStorageEnabled(true);
TwitterWebView.getSettings().setSavePassword(false);
TwitterWebView.getSettings().setSaveFormData(false);
TwitterWebView.getSettings().setSupportZoom(false);
TwitterWebView.loadUrl(url);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="wixanz.app.twitter"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".Twitter"
android:label="#string/app_name"
android:launchMode="singleInstance" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".TwitterWebView"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
<activity
android:name=".TweetList"
android:label="TweetList"
android:launchMode="singleInstance" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="callback"
android:scheme="twitter" />
</intent-filter>
</activity>
</application>
</manifest>
I did the same about others networks like LinkedIn, Foursquare. But instead of use the callback URL, I override the method shouldOverrideUrlLoading (WebView view, String url) in your WebViewClient (which is used to show the login page) to catch the access token and the token secret (if needed) by myself.